Skip to content

Commit dc67651

Browse files
[ESLint] Drive lint warnings to zero
`regexp/recommended` was added unintentionally during the ESLint v9 migration (cbfeb53) and overrode the curated regex ruleset. Remove that spread so the hand-picked list at the top of eslint.config.mjs is the active policy. Re-add 11 bug-catching rules from `recommended` that don't fight Prism's grammar idioms. Disable `prefer-const` to match team convention. Add globals for `src/plugins/**/demo.js`. Apply minor auto-fixes and inline-disable 4 intentional regex patterns. 869 warnings → 0; lint:ci, build, typecheck, tests, and regex-coverage all pass.
1 parent 1290824 commit dc67651

9 files changed

Lines changed: 40 additions & 8 deletions

File tree

eslint.config.mjs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const config = [
3939
'object-shorthand': ['warn', 'always', { avoidQuotes: true }],
4040
'one-var': ['warn', 'never'],
4141
'prefer-arrow-callback': 'warn',
42-
'prefer-const': ['warn', { 'destructuring': 'all' }],
42+
'prefer-const': 'off',
4343
'prefer-spread': 'warn',
4444

4545
// JSDoc
@@ -86,6 +86,22 @@ const config = [
8686
'regexp/sort-flags': 'warn',
8787
'regexp/strict': 'warn',
8888

89+
// Bug-catching rules ported from `regexp/recommended`. We don't extend the full
90+
// recommended set because most of its remaining rules either flag intentional
91+
// Prism grammar patterns (multi-line block matchers, `<MOD>` template substitution,
92+
// `[^\s\S]` recursion terminators, `[\r\n]` line endings) or are pure style.
93+
'regexp/no-empty-group': 'warn',
94+
'regexp/no-empty-string-literal': 'warn',
95+
'regexp/no-escape-backspace': 'warn',
96+
'regexp/no-invalid-regexp': 'warn',
97+
'regexp/no-invisible-character': 'warn',
98+
'regexp/no-legacy-features': 'warn',
99+
'regexp/no-missing-g-flag': 'warn',
100+
'regexp/no-non-standard-flag': 'warn',
101+
'regexp/no-potentially-useless-backreference': 'warn',
102+
'regexp/no-useless-backreference': 'warn',
103+
'regexp/no-useless-dollar-replacements': 'warn',
104+
89105
// I turned this rule off because we use `hasOwnProperty` in a lot of places
90106
// TODO: Think about re-enabling this rule
91107
'no-prototype-builtins': 'off',
@@ -115,7 +131,6 @@ const config = [
115131
},
116132
rules: {
117133
...eslintCommentsPlugin.configs.recommended.rules,
118-
...regexpPlugin.configs.recommended.rules,
119134

120135
'no-use-before-define': 'off',
121136

@@ -150,6 +165,22 @@ const config = [
150165
},
151166
},
152167
},
168+
{
169+
// Plugin demo pages — load these globals via <script> tags on the demo HTML
170+
files: ['src/plugins/**/demo.js'],
171+
languageOptions: {
172+
globals: {
173+
Prism: 'readonly',
174+
JSZip: 'readonly',
175+
components: 'readonly',
176+
saveAs: 'readonly',
177+
},
178+
},
179+
rules: {
180+
// Demo scripts expose globals consumed by HTML attributes (e.g. data-adapter="...")
181+
'no-unused-vars': 'off',
182+
},
183+
},
153184
{
154185
// Test files
155186
files: ['tests/**'],

src/languages/docker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515

1616
const string = /"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"|'(?:[^'\\\r\n]|\\(?:\r\n|[\s\S]))*'/
1717
.source;
18+
// eslint-disable-next-line regexp/no-dupe-disjunctions -- the (?!["']) lookahead makes the unquoted alternative disjoint from <STR>
1819
const option = /--[\w-]+=(?:<STR>|(?!["'])(?:[^\s\\]|\\.)+)/.source.replace(
1920
/<STR>/g,
2021
() => string

src/languages/markdown.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { getTextContent } from '../core/classes/token.js';
2-
import { withoutTokenize } from '../util/language-util.js';
31
import markup from './markup.js';
42

53
/** @type {import('../types.d.ts').LanguageProto<'markdown'>} */

src/languages/mongodb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export default {
288288
},
289289
'builtin': {
290290
$before: 'constant',
291+
// eslint-disable-next-line regexp/sort-alternatives -- builtinFunctions order kept semantic, not alphabetical
291292
pattern: RegExp('\\b(?:' + builtinFunctions.join('|') + ')\\b'),
292293
alias: 'keyword',
293294
},

src/languages/promql.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default {
3939
},
4040
'vector-match': {
4141
// Match the comma-separated label lists inside vector matching:
42+
// eslint-disable-next-line regexp/sort-alternatives -- vectorMatching kept in PromQL docs order
4243
pattern: new RegExp('((?:' + vectorMatching.join('|') + ')\\s*)\\([^)]*\\)'),
4344
lookbehind: true,
4445
inside: {
@@ -86,6 +87,7 @@ export default {
8687
},
8788
},
8889
],
90+
// eslint-disable-next-line regexp/sort-alternatives -- keywords concatenates semantically-ordered groups
8991
'keyword': new RegExp('\\b(?:' + keywords.join('|') + ')\\b', 'i'),
9092
'function': /\b[a-z_]\w*(?=\s*\()/i,
9193
'number':

src/languages/python.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default {
5858
},
5959
},
6060
'keyword':
61-
/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield|lazy)\b/,
61+
/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|lazy|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
6262
'builtin':
6363
/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
6464
'boolean': /\b(?:False|None|True)\b/,

src/plugins/autoloader/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ document.querySelector('.download-grammars').addEventListener('click', async ({
4444
continue;
4545
}
4646
let basepath =
47-
'https://dev.prismjs.com/' + components.languages.meta.path.replace(/\{id}/g, id);
47+
'https://dev.prismjs.com/' + components.languages.meta.path.replace(/\{id\}/g, id);
4848
let basename = basepath.substring(basepath.lastIndexOf('/') + 1);
4949
files.push([basename + '.js', basepath + '.js']);
5050
files.push([basename + '.min.js', basepath + '.min.js']);

src/plugins/toolbar/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Prism.plugins.toolbar.registerButton('hello-world', {
22
text: 'Hello World!', // required
3-
onClick: function (env) {
3+
onClick (env) {
44
// optional
55
alert(`This code snippet is written in ${env.language}.`);
66
},

src/util/async.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export async function allSettled (promises) {
6767
/**
6868
* @template T
6969
* @typedef {Promise<T> & {resolve: (value: T) => void, reject: (reason?: any) => void}} DeferredPromise<T>
70-
*
7170
*/
7271

7372
/**

0 commit comments

Comments
 (0)