Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: lint eleventy config file #15904

Merged
merged 5 commits into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,6 +1,7 @@
/build/**
/coverage/**
/docs/**
!/docs/.eleventy.js
/jsdoc/**
/templates/**
/tests/bench/**
Expand Down
30 changes: 20 additions & 10 deletions .eslintrc.js
Expand Up @@ -46,8 +46,7 @@ module.exports = {
"internal-rules"
],
extends: [
"eslint",
"plugin:eslint-plugin/recommended"
"eslint"
],
parserOptions: {
ecmaVersion: 2021
Expand All @@ -63,14 +62,6 @@ module.exports = {
}
},
rules: {
"eslint-plugin/prefer-message-ids": "error",
"eslint-plugin/prefer-output-null": "error",
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-docs-description": "error",
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-shorthand-strings": "error",
"internal-rules/multiline-comment-style": "error"
},
overrides: [
Expand All @@ -83,7 +74,15 @@ module.exports = {
{
files: ["lib/rules/*", "tools/internal-rules/*"],
excludedFiles: ["index.js"],
extends: [
"plugin:eslint-plugin/rules-recommended"
],
rules: {
"eslint-plugin/prefer-message-ids": "error",
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-docs-description": "error",
"internal-rules/no-invalid-meta": "error"
}
},
Expand All @@ -94,6 +93,17 @@ module.exports = {
"eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/rules/{{name}}" }]
}
},
{
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
extends: [
"plugin:eslint-plugin/tests-recommended"
],
rules: {
"eslint-plugin/prefer-output-null": "error",
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-shorthand-strings": "error"
}
},
{
files: ["tests/**/*"],
env: { mocha: true },
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -22,6 +22,11 @@ jobs:
run: node Makefile checkRuleFiles
- name: Check Licenses
run: node Makefile checkLicenses
- name: Install Docs Packages
working-directory: docs
run: npm install
- name: Lint Docs JS Files
run: node Makefile lintDocsJS

test_on_node:
name: Test
Expand Down
26 changes: 25 additions & 1 deletion Makefile.js
Expand Up @@ -482,8 +482,17 @@ target.lint = function([fix = false] = []) {
let errors = 0,
lastReturn;

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

target.lintDocsJS = function([fix = false] = []) {
let errors = 0;

echo("Validating JavaScript files in the docs directory");
const lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} docs`);

if (lastReturn.code !== 0) {
errors++;
}

if (errors) {
exit(1);
}
};

target.fuzz = function({ amount = 1000, fuzzBrokenAutofixes = false } = {}) {
const fuzzerRunner = require("./tools/fuzzer-runner");
const fuzzResults = fuzzerRunner.run({ amount, fuzzBrokenAutofixes });
Expand Down