Skip to content

Commit

Permalink
Add rules and plugins to ESLint (mdn#16370)
Browse files Browse the repository at this point in the history
* Add ESLint (using Standard styling)

* Add ESLint to npm run lint command

* Update package-lock.json

* Place ESLint after test/lint

* Add ESLint to fix command

* Update ESLint rules

* Use semicolons for separate commands

* Fix ESLint quotation rule

* Add TypeScript files in root to ESLint rules

* Run Prettier formatting

* Tell ESLint not to conflict with Prettier

* Fix security audit

* Disable no-console ESLint rule

* Let Prettier handle indenations

* Integrate ESLint into linter/fix scripts

* Fix bad merge

* Update ESLint

* Integrate Prettier into ESLint

* Remove stdio: inherit and force colors

* Lint JSDoc comments

* Label changes to .eslintrc.json as infra

* Install eslint-plugin-jsdoc as a dev dependency

* Allow empty catch block in try-catch

* Require JSDoc for any function/method/class

* Separate Prettier call for Markdown files

* Warn when function has no description

* Add JSDoc to format fix script

* Prefer arrow function syntax

* Fix formatting for TypeScript files

* Update JSDocs

* Update ESLint and its dependencies

* Add additional rules and sort alphabetically

* Prefer const over let

* Update package-lock.json

* Update package-lock.json

* Fix commands

* Fix commands

* Update eslint-plugin-jsdoc

* Fix typo

* Use TS no-extra-parens rule

* Run fix script

* Update quotes rule to avoid escapes

* Convert to arrow functions; update some typedefs

* Prefer typescript-eslint rule extensions

* Make fix script asynchronous

* Run fix script and manually fix many issues

* Require some JSDoc declarations

* Fix more issues

* Use prefer-arrow-functions plugin

* Run fix script

* Remove no-extra-parens rule (conflicts with Prettier)

* Disable default-case

* Fix remaining issues

* Silence warnings in fix script

* Update rules

* Fix remaining errors

* Fix TypeScript issues
  • Loading branch information
queengooborg authored Aug 4, 2022
1 parent 825b341 commit 989c124
Show file tree
Hide file tree
Showing 63 changed files with 1,353 additions and 621 deletions.
55 changes: 52 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
"jest": true,
"node": true
},
"plugins": ["@typescript-eslint", "prettier"],
"plugins": [
"@typescript-eslint",
"prettier",
"jsdoc",
"prefer-arrow-functions"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:jsdoc/recommended"
],
"globals": {
"Atomics": "readonly",
Expand All @@ -20,7 +26,50 @@
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/quotes": ["error", "single", { "avoidEscape": true }],
"consistent-return": "error",
"curly": "error",
"default-case": "off",
"default-case-last": "error",
"jsdoc/check-param-names": "error",
"jsdoc/require-description": "warn",
"jsdoc/require-jsdoc": [
"warn",
{
"require": {
"ArrowFunctionExpression": true,
"ClassDeclaration": true,
"ClassExpression": true,
"FunctionDeclaration": true,
"FunctionExpression": true,
"MethodDefinition": true
}
}
],
"jsdoc/require-param-type": "error",
"jsdoc/require-returns": "error",
"jsdoc/require-returns-type": "error",
"jsdoc/no-undefined-types": "error",
"jsdoc/require-yields": "error",
"linebreak-style": ["error", "unix"],
"no-console": "off",
"no-else-return": "error",
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-eval": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-return-assign": "error",
"no-self-compare": "error",
"no-unused-expressions": "off",
"no-useless-call": "error",
"prefer-arrow-functions/prefer-arrow-functions": [
"error",
{ "returnStyle": "implicit" }
],
"prefer-const": "error",
"prettier/prettier": "error",
"@typescript-eslint/no-explicit-any": "off"
"quotes": "off"
}
}
8 changes: 5 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const dirname = fileURLToPath(new URL('.', import.meta.url));
* @param {string[]} dirs The directories to load
* @returns {object} All of the browser compatibility data
*/
async function load(...dirs: string[]) {
const load = async (...dirs: string[]) => {
const result = {};

for (const dir of dirs) {
Expand All @@ -38,7 +38,9 @@ async function load(...dirs: string[]) {
// Add source_file props
const walker = walk(undefined, contents);
for (const { compat } of walker) {
if (!compat) continue;
if (!compat) {
continue;
}

compat.source_file = normalizePath(path.relative(dirname, fp));
}
Expand All @@ -52,7 +54,7 @@ async function load(...dirs: string[]) {
}

return result;
}
};

export default (await load(
'api',
Expand Down
135 changes: 135 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"eslint-config-prettier": "~8.5.0",
"eslint-config-standard": "~17.0.0",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-jsdoc": "~39.3.4",
"eslint-plugin-node": "~11.1.0",
"eslint-plugin-prefer-arrow-functions": "~3.1.4",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-promise": "~6.0.0",
"fast-json-stable-stringify": "~2.1.0",
Expand All @@ -71,7 +73,7 @@
"unittest": "c8 mocha index.test.ts --recursive \"{,!(node_modules)/**}/*.test.ts\"",
"coverage": "c8 report -r lcov && open-cli coverage/lcov-report/index.html",
"format": "npx eslint \"**/*.ts\" && npx prettier --check \"**/*.md\" \"**/*.json\"",
"format:fix": "npx eslint --fix \"**/*.ts\" && npx prettier --write \"**/*.md\" \"**/*.json\"",
"format:fix": "npx eslint --quiet --fix \"**/*.ts\" && npx prettier --write \"**/*.md\" \"**/*.json\"",
"lint": "ts-node test/lint.ts",
"fix": "npm run format:fix && ts-node scripts/fix/index.ts",
"stats": "ts-node scripts/statistics.ts",
Expand Down
Loading

0 comments on commit 989c124

Please sign in to comment.