Skip to content

Commit 5f5c1fb

Browse files
authored
chore: lint eleventy config file (#15904)
* chore: lint eleventy config file * fix wrong override for eslint-plugin/prefer-output-null * update `lint` command to exclude linting JS files in the docs dir * add separate script from linting docs js files * use internal mutliline comment style for sections
1 parent 8513d37 commit 5f5c1fb

8 files changed

Lines changed: 209 additions & 153 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/build/**
22
/coverage/**
33
/docs/**
4+
!/docs/.eleventy.js
45
/jsdoc/**
56
/templates/**
67
/tests/bench/**

.eslintrc.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ module.exports = {
4646
"internal-rules"
4747
],
4848
extends: [
49-
"eslint",
50-
"plugin:eslint-plugin/recommended"
49+
"eslint"
5150
],
5251
parserOptions: {
5352
ecmaVersion: 2021
@@ -63,14 +62,6 @@ module.exports = {
6362
}
6463
},
6564
rules: {
66-
"eslint-plugin/prefer-message-ids": "error",
67-
"eslint-plugin/prefer-output-null": "error",
68-
"eslint-plugin/prefer-placeholders": "error",
69-
"eslint-plugin/prefer-replace-text": "error",
70-
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
71-
"eslint-plugin/require-meta-docs-description": "error",
72-
"eslint-plugin/test-case-property-ordering": "error",
73-
"eslint-plugin/test-case-shorthand-strings": "error",
7465
"internal-rules/multiline-comment-style": "error"
7566
},
7667
overrides: [
@@ -83,7 +74,15 @@ module.exports = {
8374
{
8475
files: ["lib/rules/*", "tools/internal-rules/*"],
8576
excludedFiles: ["index.js"],
77+
extends: [
78+
"plugin:eslint-plugin/rules-recommended"
79+
],
8680
rules: {
81+
"eslint-plugin/prefer-message-ids": "error",
82+
"eslint-plugin/prefer-placeholders": "error",
83+
"eslint-plugin/prefer-replace-text": "error",
84+
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
85+
"eslint-plugin/require-meta-docs-description": "error",
8786
"internal-rules/no-invalid-meta": "error"
8887
}
8988
},
@@ -94,6 +93,17 @@ module.exports = {
9493
"eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/rules/{{name}}" }]
9594
}
9695
},
96+
{
97+
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
98+
extends: [
99+
"plugin:eslint-plugin/tests-recommended"
100+
],
101+
rules: {
102+
"eslint-plugin/prefer-output-null": "error",
103+
"eslint-plugin/test-case-property-ordering": "error",
104+
"eslint-plugin/test-case-shorthand-strings": "error"
105+
}
106+
},
97107
{
98108
files: ["tests/**/*"],
99109
env: { mocha: true },

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
run: node Makefile checkRuleFiles
2323
- name: Check Licenses
2424
run: node Makefile checkLicenses
25+
- name: Install Docs Packages
26+
working-directory: docs
27+
run: npm install
28+
- name: Lint Docs JS Files
29+
run: node Makefile lintDocsJS
2530

2631
test_on_node:
2732
name: Test

Makefile.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,17 @@ target.lint = function([fix = false] = []) {
482482
let errors = 0,
483483
lastReturn;
484484

485+
/*
486+
* In order to successfully lint JavaScript files in the `docs` directory, dependencies declared in `docs/package.json`
487+
* would have to be installed in `docs/node_modules`. In particular, eslint-plugin-node rules examine `docs/node_modules`
488+
* when analyzing `require()` calls from CJS modules in the `docs` directory. Since our release process does not run `npm install`
489+
* in the `docs` directory, linting would fail and break the release. Also, working on the main `eslint` package does not require
490+
* installing dependencies declared in `docs/package.json`, so most contributors will not have `docs/node_modules` locally.
491+
* Therefore, we add `--ignore-pattern docs` to exclude linting the `docs` directory from this command.
492+
* There is a separate command `target.lintDocsJS` for linting JavaScript files in the `docs` directory.
493+
*/
485494
echo("Validating JavaScript files");
486-
lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} .`);
495+
lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} . --ignore-pattern docs`);
487496
if (lastReturn.code !== 0) {
488497
errors++;
489498
}
@@ -502,6 +511,21 @@ target.lint = function([fix = false] = []) {
502511
}
503512
};
504513

514+
target.lintDocsJS = function([fix = false] = []) {
515+
let errors = 0;
516+
517+
echo("Validating JavaScript files in the docs directory");
518+
const lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} docs`);
519+
520+
if (lastReturn.code !== 0) {
521+
errors++;
522+
}
523+
524+
if (errors) {
525+
exit(1);
526+
}
527+
};
528+
505529
target.fuzz = function({ amount = 1000, fuzzBrokenAutofixes = false } = {}) {
506530
const fuzzerRunner = require("./tools/fuzzer-runner");
507531
const fuzzResults = fuzzerRunner.run({ amount, fuzzBrokenAutofixes });

0 commit comments

Comments
 (0)