Skip to content

Commit 0748e49

Browse files
authored
chore(eslint): update config to catch .only and .skip files (#5303)
* chore(eslint): only ignore fixture JS files * chore(eslint): update config to catch .only and .skip files * chore(eslint): make .skip file comment valid js
1 parent 4b3dc34 commit 0748e49

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

eslint.config.mjs

+24-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import js from '@eslint/js';
1212
import tseslint from 'typescript-eslint';
1313
import gitignore from 'eslint-config-flat-gitignore';
1414
import vitest from '@vitest/eslint-plugin';
15+
import * as espree from 'espree';
16+
1517
import { PUBLIC_PACKAGES as publicPackageData } from './scripts/shared/packages.mjs';
1618
// convert filepath to eslint glob
1719
const PUBLIC_PACKAGES = publicPackageData.map(({ path }) => `${path}/**`);
@@ -27,7 +29,7 @@ export default tseslint.config(
2729

2830
gitignore(),
2931
{
30-
ignores: ['**/fixtures'],
32+
ignores: ['packages/**/fixtures/**/*.js'],
3133
},
3234
js.configs.recommended,
3335
...tseslint.configs.recommendedTypeChecked,
@@ -403,18 +405,35 @@ export default tseslint.config(
403405

404406
{
405407
// These are empty files used to help debug test fixtures
406-
files: ['**/.only'],
408+
files: ['**/.only', '**/.skip'],
407409
plugins: { '@lwc/lwc-internal': lwcInternal },
410+
languageOptions: {
411+
// Using the default eslint parser because typescript-eslint doesn't
412+
// seem to correctly support `extraFileExtensions`
413+
parser: espree,
414+
parserOptions: {
415+
extraFileExtensions: ['only', 'skip'],
416+
},
417+
},
408418
rules: {
409419
'@lwc/lwc-internal/forbidden-filename': 'error',
420+
// Disable all TS rules because they complain about the parser being espree
421+
...Object.fromEntries(
422+
tseslint.configs.all
423+
.flatMap((cfg) => Object.keys(cfg.rules ?? {}))
424+
.map((rule) => [rule, 'off'])
425+
),
410426
},
411427
},
412428
{
413-
// These are empty files used to help debug test fixtures
414429
files: ['**/.skip'],
415-
plugins: { '@lwc/lwc-internal': lwcInternal },
416430
rules: {
417-
'@lwc/lwc-internal/forbidden-filename': 'off',
431+
// We want to avoid accidentally committing .skip files, but sometimes there are
432+
// legitimate reasons to do so. So we complain when trying to commit, but not any
433+
// other time.
434+
'@lwc/lwc-internal/forbidden-filename':
435+
// eslint-disable-next-line no-undef
436+
process.env.npm_lifecycle_event === 'lint-staged' ? 'error' : 'off',
418437
},
419438
}
420439
);

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@
7676
"vitest": "^3.0.8"
7777
},
7878
"lint-staged": {
79-
"*.{js,mjs,ts}": "eslint --cache",
79+
"*.{js,mjs,ts,only,skip}": "eslint --cache",
8080
"*.{css,js,json,md,mjs,ts,yaml,yml}": "prettier --check",
8181
"{packages/**/package.json,scripts/tasks/check-and-rewrite-package-json.js}": "node ./scripts/tasks/check-and-rewrite-package-json.js --test",
82-
"{LICENSE-CORE.md,**/LICENSE.md,yarn.lock,scripts/tasks/generate-license-files.js,scripts/shared/bundled-dependencies.js}": "node ./scripts/tasks/generate-license-files.js --test",
83-
"*.{only,skip}": "eslint --cache --plugin '@lwc/eslint-plugin-lwc-internal' --rule '@lwc/lwc-internal/forbidden-filename: error'"
82+
"{LICENSE-CORE.md,**/LICENSE.md,yarn.lock,scripts/tasks/generate-license-files.js,scripts/shared/bundled-dependencies.js}": "node ./scripts/tasks/generate-license-files.js --test"
8483
},
8584
"workspaces": [
8685
"packages/@lwc/*",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
W-17972327
1+
// W-17972327
22

3-
This test fails in CI and has been doing so intermittently in recent PRs. Unfortunately, it has been difficult to reproduce and resolve when running locally. Since the failure is unrelated to this PR, we're disabling the test and have filed a work item (reference above) to investigate separately.
3+
// This test fails in CI and has been doing so intermittently in recent PRs. Unfortunately, it has been difficult to reproduce and resolve when running locally. Since the failure is unrelated to this PR, we're disabling the test and have filed a work item (reference above) to investigate separately.
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12
import Extension from 'x/ext-ts';

0 commit comments

Comments
 (0)