]> git.proxmox.com Git - pve-eslint.git/blame - eslint/.eslintrc.js
import 8.23.1 source
[pve-eslint.git] / eslint / .eslintrc.js
CommitLineData
8f9d1d4d
DC
1/*
2 * IMPORTANT!
3 *
4 * Any changes made to this file must also be made to eslint.config.js.
5 *
6 * Internally, ESLint is using the eslint.config.js file to lint itself.
7 * This file is needed too, because:
8 *
9 * 1. There are tests that expect .eslintrc.js to be present to actually run.
10 * 2. ESLint VS Code extension expects eslintrc config files to be
11 * present to work correctly.
12 *
13 * Once we no longer need to support both eslintrc and flat config, we will
14 * remove this file.
15 */
16
17
eb39fafa
DC
18"use strict";
19
56c4a2cb
DC
20const path = require("path");
21
22const INTERNAL_FILES = {
23 CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
56c4a2cb
DC
24 LINTER_PATTERN: "lib/linter/**/*",
25 RULE_TESTER_PATTERN: "lib/rule-tester/**/*",
26 RULES_PATTERN: "lib/rules/**/*",
27 SOURCE_CODE_PATTERN: "lib/source-code/**/*"
28};
29
30/**
31 * Resolve an absolute path or glob pattern.
32 * @param {string} pathOrPattern the path or glob pattern.
33 * @returns {string} The resolved path or glob pattern.
34 */
35function resolveAbsolutePath(pathOrPattern) {
36 return path.resolve(__dirname, pathOrPattern);
37}
38
39/**
40 * Create an array of `no-restricted-require` entries for ESLint's core files.
41 * @param {string} [pattern] The glob pattern to create the entries for.
42 * @returns {Object[]} The array of `no-restricted-require` entries.
43 */
44function createInternalFilesPatterns(pattern = null) {
45 return Object.values(INTERNAL_FILES)
46 .filter(p => p !== pattern)
47 .map(p => ({
48 name: [
49
50 // Disallow all children modules.
51 resolveAbsolutePath(p),
52
53 // Allow the main `index.js` module.
54 `!${resolveAbsolutePath(p.replace(/\*\*\/\*$/u, "index.js"))}`
55 ]
56 }));
57}
eb39fafa
DC
58
59module.exports = {
60 root: true,
61 plugins: [
62 "eslint-plugin",
63 "internal-rules"
64 ],
65 extends: [
8f9d1d4d 66 "eslint"
eb39fafa
DC
67 ],
68 parserOptions: {
609c276f 69 ecmaVersion: 2021
eb39fafa 70 },
56c4a2cb
DC
71
72 /*
73 * it fixes eslint-plugin-jsdoc's reports: "Invalid JSDoc tag name "template" jsdoc/check-tag-names"
74 * refs: https://github.com/gajus/eslint-plugin-jsdoc#check-tag-names
75 */
76 settings: {
77 jsdoc: {
78 mode: "typescript"
79 }
80 },
eb39fafa 81 rules: {
eb39fafa
DC
82 "internal-rules/multiline-comment-style": "error"
83 },
84 overrides: [
8f9d1d4d
DC
85 {
86 files: ["tools/*.js"],
87 rules: {
88 "no-console": "off"
89 }
90 },
eb39fafa
DC
91 {
92 files: ["lib/rules/*", "tools/internal-rules/*"],
93 excludedFiles: ["index.js"],
8f9d1d4d
DC
94 extends: [
95 "plugin:eslint-plugin/rules-recommended"
96 ],
eb39fafa 97 rules: {
8f9d1d4d
DC
98 "eslint-plugin/no-missing-message-ids": "error",
99 "eslint-plugin/no-unused-message-ids": "error",
100 "eslint-plugin/prefer-message-ids": "error",
101 "eslint-plugin/prefer-placeholders": "error",
102 "eslint-plugin/prefer-replace-text": "error",
103 "eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
104 "eslint-plugin/require-meta-docs-description": ["error", { pattern: "^(Enforce|Require|Disallow)" }],
609c276f 105 "internal-rules/no-invalid-meta": "error"
eb39fafa
DC
106 }
107 },
108 {
109 files: ["lib/rules/*"],
110 excludedFiles: ["index.js"],
111 rules: {
609c276f 112 "eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/rules/{{name}}" }]
eb39fafa
DC
113 }
114 },
8f9d1d4d
DC
115 {
116 files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
117 extends: [
118 "plugin:eslint-plugin/tests-recommended"
119 ],
120 rules: {
121 "eslint-plugin/prefer-output-null": "error",
122 "eslint-plugin/test-case-property-ordering": "error",
123 "eslint-plugin/test-case-shorthand-strings": "error"
124 }
125 },
eb39fafa
DC
126 {
127 files: ["tests/**/*"],
128 env: { mocha: true },
129 rules: {
130 "no-restricted-syntax": ["error", {
131 selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']",
132 message: "`assert.doesNotThrow()` should be replaced with a comment next to the code."
133 }]
134 }
135 },
136
137 // Restrict relative path imports
138 {
139 files: ["lib/*"],
609c276f 140 excludedFiles: ["lib/unsupported-api.js"],
eb39fafa 141 rules: {
8f9d1d4d 142 "n/no-restricted-require": ["error", [
56c4a2cb
DC
143 ...createInternalFilesPatterns()
144 ]]
eb39fafa
DC
145 }
146 },
147 {
56c4a2cb 148 files: [INTERNAL_FILES.CLI_ENGINE_PATTERN],
eb39fafa 149 rules: {
8f9d1d4d
DC
150 "n/no-restricted-require": ["error", [
151 ...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN)
56c4a2cb 152 ]]
eb39fafa
DC
153 }
154 },
155 {
56c4a2cb 156 files: [INTERNAL_FILES.LINTER_PATTERN],
eb39fafa 157 rules: {
8f9d1d4d 158 "n/no-restricted-require": ["error", [
56c4a2cb
DC
159 ...createInternalFilesPatterns(INTERNAL_FILES.LINTER_PATTERN),
160 "fs",
161 resolveAbsolutePath("lib/cli-engine/index.js"),
56c4a2cb
DC
162 resolveAbsolutePath("lib/rule-tester/index.js")
163 ]]
eb39fafa
DC
164 }
165 },
166 {
56c4a2cb 167 files: [INTERNAL_FILES.RULES_PATTERN],
eb39fafa 168 rules: {
8f9d1d4d 169 "n/no-restricted-require": ["error", [
56c4a2cb
DC
170 ...createInternalFilesPatterns(INTERNAL_FILES.RULES_PATTERN),
171 "fs",
172 resolveAbsolutePath("lib/cli-engine/index.js"),
56c4a2cb
DC
173 resolveAbsolutePath("lib/linter/index.js"),
174 resolveAbsolutePath("lib/rule-tester/index.js"),
175 resolveAbsolutePath("lib/source-code/index.js")
176 ]]
eb39fafa
DC
177 }
178 },
179 {
180 files: ["lib/shared/**/*"],
181 rules: {
8f9d1d4d 182 "n/no-restricted-require": ["error", [
56c4a2cb
DC
183 ...createInternalFilesPatterns(),
184 resolveAbsolutePath("lib/cli-engine/index.js"),
56c4a2cb
DC
185 resolveAbsolutePath("lib/linter/index.js"),
186 resolveAbsolutePath("lib/rule-tester/index.js"),
187 resolveAbsolutePath("lib/source-code/index.js")
188 ]]
eb39fafa
DC
189 }
190 },
191 {
56c4a2cb 192 files: [INTERNAL_FILES.SOURCE_CODE_PATTERN],
eb39fafa 193 rules: {
8f9d1d4d 194 "n/no-restricted-require": ["error", [
56c4a2cb
DC
195 ...createInternalFilesPatterns(INTERNAL_FILES.SOURCE_CODE_PATTERN),
196 "fs",
197 resolveAbsolutePath("lib/cli-engine/index.js"),
56c4a2cb
DC
198 resolveAbsolutePath("lib/linter/index.js"),
199 resolveAbsolutePath("lib/rule-tester/index.js"),
200 resolveAbsolutePath("lib/rules/index.js")
201 ]]
eb39fafa
DC
202 }
203 },
204 {
56c4a2cb 205 files: [INTERNAL_FILES.RULE_TESTER_PATTERN],
eb39fafa 206 rules: {
8f9d1d4d 207 "n/no-restricted-require": ["error", [
56c4a2cb 208 ...createInternalFilesPatterns(INTERNAL_FILES.RULE_TESTER_PATTERN),
8f9d1d4d 209 resolveAbsolutePath("lib/cli-engine/index.js")
56c4a2cb 210 ]]
eb39fafa
DC
211 }
212 }
213 ]
214};