Skip to content

[p5.js 2.x] chore: enable eslint rules #7930

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

Draft
wants to merge 5 commits into
base: dev-2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@ const gitignore = fileURLToPath(new URL('.gitignore', import.meta.url));

const off = 0;
const warn = 1;
// const error = 2;

const mitigatedJsRules = Object.fromEntries(
Object.entries(js.configs.recommended.rules).map(([rule]) => [rule, warn])
);
const error = 2;

/** @type {import('eslint').Linter.RulesRecord} */
const commonRules = {
// https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
// ...js.configs.recommended.rules,
...mitigatedJsRules,
...js.configs.recommended.rules,

// https://eslint.org/docs/latest/rules/eqeqeq
eqeqeq: [warn, 'smart'],
eqeqeq: [error, 'smart'],

// https://eslint.org/docs/latest/rules/new-cap
'new-cap': off,
Expand All @@ -36,16 +31,16 @@ const commonRules = {
'no-async-promise-executor': off,

// https://eslint.org/docs/latest/rules/no-caller
'no-caller': warn,
'no-caller': error,

// https://eslint.org/docs/latest/rules/no-cond-assign
'no-cond-assign': [warn, 'except-parens'],
'no-cond-assign': [error, 'except-parens'],

// https://eslint.org/docs/latest/rules/no-console
'no-console': off,

// https://eslint.org/docs/latest/rules/no-empty
'no-empty': [warn, { allowEmptyCatch: true }],
'no-empty': [error, { allowEmptyCatch: true }],

// https://eslint.org/docs/latest/rules/no-prototype-builtins
'no-prototype-builtins': off,
Expand All @@ -55,14 +50,14 @@ const commonRules = {

// https://eslint.org/docs/latest/rules/no-unused-vars
'no-unused-vars': [
warn,
error,
{
args: 'none'
}
],

// https://eslint.org/docs/latest/rules/no-use-before-define
'no-use-before-define': [warn, { functions: false }],
'no-use-before-define': [error, { functions: false }],

// https://eslint.style/rules/js/arrow-parens#arrow-parens
'@stylistic/arrow-parens': [warn, 'as-needed'],
Expand Down Expand Up @@ -101,6 +96,7 @@ const commonRules = {
'@stylistic/semi': [warn, 'always']
};

// https://github.com/gajus/eslint-plugin-jsdoc?tab=readme-ov-file#rules
/** @type {import('eslint').Linter.RulesRecord} */
const jsdocRules = {
// https://github.com/gajus/eslint-plugin-jsdoc/blob/99cb131ee40fa10f943aadfd73a6d18da082882f/docs/rules/check-alignment.md
Expand All @@ -117,6 +113,26 @@ const jsdocRules = {
'jsdoc/require-asterisk-prefix': warn
};

// https://github.com/eslint/markdown?tab=readme-ov-file#rules
/** @type {import('eslint').Linter.RulesRecord} */
const markdownRules = {
'markdown/fenced-code-language': off,
'markdown/heading-increment': off,
'markdown/no-duplicate-definitions': warn,
'markdown/no-duplicate-headings': [warn, { checkSiblingsOnly: true }],
'markdown/no-empty-definitions': warn,
'markdown/no-empty-images': warn,
'markdown/no-empty-links': warn,
'markdown/no-html': off,
'markdown/no-invalid-label-refs': off,
'markdown/no-missing-atx-heading-space': warn,
'markdown/no-missing-label-refs': off, // @todo
'markdown/no-missing-link-fragments': off,
'markdown/no-multiple-h1': off,
'markdown/require-alt-text': warn,
'markdown/table-column-count': warn
};

export default defineConfig([
includeIgnoreFile(gitignore),
globalIgnores([
Expand Down Expand Up @@ -246,30 +262,14 @@ export default defineConfig([
markdown
},
language: 'markdown/commonmark',
rules: {
'markdown/fenced-code-language': off,
'markdown/heading-increment': off,
'markdown/no-duplicate-definitions': warn,
// 'markdown/no-duplicate-headings': ["error", { checkSiblingsOnly: true }], // @todo waiting for @eslint/[email protected]
'markdown/no-empty-definitions': warn,
'markdown/no-empty-images': warn,
'markdown/no-empty-links': warn,
'markdown/no-html': off,
'markdown/no-invalid-label-refs': off,
'markdown/no-missing-atx-heading-space': warn,
'markdown/no-missing-label-refs': off, // @todo
'markdown/no-missing-link-fragments': off,
'markdown/no-multiple-h1': off,
'markdown/require-alt-text': warn,
'markdown/table-column-count': warn
}
}
rules: markdownRules
},
// https://github.com/eslint/markdown?tab=readme-ov-file#file-name-details
// @todo
// works out of the box but results in some `Parsing error`s
// which will make github workflows & actions fail e.g.
// * contributor_docs/fes_contribution_guide.md 354:1 error Parsing error: Unexpected character '🌸'
// * contributor_docs/zh-Hans/unit_testing.md 35:1 error Parsing error: Unexpected token
// * rfc_p5js_2.md 205:50 error Parsing error: Binding arguments in strict mode
// ...markdown.configs.processor
...markdown.configs.processor
]);
19 changes: 15 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@eslint/compat": "^1.2.9",
"@eslint/js": "^9.28.0",
"@eslint/markdown": "^6.5.0",
"@eslint/markdown": "^6.6.0",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
Expand Down
Loading