forked from WordPress/openverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.mjs
70 lines (62 loc) · 2.1 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { fileURLToPath } from "node:url"
import path from "node:path"
import fs from "node:fs"
// eslint-disable-next-line import/no-unresolved
import { config as defineConfig } from "typescript-eslint"
import { convertIgnorePatternToMinimatch } from "@eslint/compat"
import openverse from "@openverse/eslint-plugin"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const gitignoreFiles = [
path.resolve(__dirname, ".gitignore"),
path.resolve(__dirname, "frontend", ".gitignore"),
path.resolve(__dirname, "automations", "js", ".gitignore"),
path.resolve(__dirname, "packages", "js", "api-client", ".gitignore"),
]
/**
* Vendored in from `@eslint/compat` to support multiple ignore files.
* Reads an ignore file and returns a list of ignore patterns.
* @param {string[]} ignoreFilePaths The absolute path to the ignore file.
* @returns {string[]} An array of ignore patterns.
* @throws {Error} If the ignore file path is not an absolute path.
*/
function mapIgnoreFiles(ignoreFilePaths) {
for (const ignoreFilePath of ignoreFilePaths) {
if (!path.isAbsolute(ignoreFilePath)) {
throw new Error("The ignore file location must be an absolute path.")
}
}
/** @type {string[]} */
const ignores = []
for (const ignoreFilePath of ignoreFilePaths) {
const ignoreFile = fs.readFileSync(ignoreFilePath, "utf8")
const lines = ignoreFile.split(/\r?\n/u)
ignores.push(
...lines
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("#"))
.map(convertIgnorePatternToMinimatch)
)
}
return ignores
}
// List of files from old .eslintignore
const eslintIgnores = [
"**/dist/**",
"frontend/.pnpm-store/**",
"frontend/.nuxt/**",
"frontend/.output/**",
"frontend/.remake/**",
"frontend/src/locales/*.json",
"**/coverage/**",
"frontend/test/tapes/**",
"frontend/storybook-static/**",
"packages/**/dist/**",
]
export default defineConfig(
{
name: "openverse:ignore-files",
ignores: [...mapIgnoreFiles(gitignoreFiles), ...eslintIgnores],
},
{ files: [".pnpmfile.cjs"] },
...openverse.default.configs.project
)