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