Download next.js/packages/eslint-plugin-next/src/utils/get-root-dirs.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/eslint-plugin-next/src/utils/get-root-dirs.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/eslint-plugin-next/src/utils/get-root-dirs.ts
-
curl -L -o get-root-dirs.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/eslint-plugin-next/src/utils/get-root-dirs.ts
804 Bytes
| import { globSync } from 'fast-glob' | |
| import type { Rule } from 'eslint' | |
| /** | |
| * Process a Next.js root directory glob. | |
| */ | |
| const processRootDir = (rootDir: string): string[] => { | |
| return globSync(rootDir.replace(/\\/g, '/'), { | |
| onlyDirectories: true, | |
| }) | |
| } | |
| /** | |
| * Gets one or more Root, returns an array of root directories. | |
| */ | |
| export const getRootDirs = (context: Rule.RuleContext) => { | |
| let rootDirs = [context.cwd] | |
| const nextSettings: { rootDir?: string | string[] } = | |
| context.settings.next || {} | |
| let rootDir = nextSettings.rootDir | |
| if (typeof rootDir === 'string') { | |
| rootDirs = processRootDir(rootDir) | |
| } else if (Array.isArray(rootDir)) { | |
| rootDirs = rootDir | |
| .map((dir) => (typeof dir === 'string' ? processRootDir(dir) : [])) | |
| .flat() | |
| } | |
| return rootDirs | |
| } | |