useLints.ts26 lines · main
| 1 | import { useParams } from 'common' |
| 2 | |
| 3 | import { useProjectLintsQuery } from '@/data/lint/lint-query' |
| 4 | |
| 5 | /** |
| 6 | * Hook to fetch and filter project lints |
| 7 | * |
| 8 | * Retrieves all lints for the current project and filters them by: |
| 9 | * - Security-related lints |
| 10 | * - Error-level security lints |
| 11 | * |
| 12 | * @returns {Object} Object containing filtered lint arrays |
| 13 | * @returns {Array} securityLints - All security-related lints |
| 14 | * @returns {Array} errorLints - Security lints with ERROR level |
| 15 | */ |
| 16 | export const useLints = () => { |
| 17 | const { ref } = useParams() |
| 18 | const { data } = useProjectLintsQuery({ |
| 19 | projectRef: ref, |
| 20 | }) |
| 21 | |
| 22 | const securityLints = (data ?? []).filter((lint) => lint.categories.includes('SECURITY')) |
| 23 | const errorLints = securityLints.filter((lint) => lint.level === 'ERROR') |
| 24 | |
| 25 | return { securityLints, errorLints } |
| 26 | } |