-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Switch to eslint-plugin-jsdoc to replace obsolete ESLint rules. * Drop support for ESLint v6 and v7, and support for Node 14 and Node 16. * Switch to flat config setup for ESLint * Switch to ESLint v9 and get tests passing. * Update plugin configuration to export in ESLint v8 and v9 formats. * Rename configurations, use file handling for package.json read, simplify default rulesets.
- Loading branch information
Showing
12 changed files
with
693 additions
and
456 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import globals from "globals"; | ||
import js from "@eslint/js"; | ||
import jsdoc from "eslint-plugin-jsdoc"; | ||
import eslintConfigPrettier from "eslint-config-prettier"; | ||
|
||
export default [ | ||
{ | ||
languageOptions: { | ||
ecmaVersion: "latest", | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
}, | ||
}, | ||
}, | ||
js.configs.recommended, | ||
{ | ||
rules: { | ||
"lines-around-comment": [ | ||
"error", | ||
{ | ||
allowArrayStart: true, | ||
allowBlockStart: true, | ||
allowObjectStart: true, | ||
beforeBlockComment: false, | ||
beforeLineComment: true, | ||
}, | ||
], | ||
"prefer-template": ["error"], | ||
"object-shorthand": ["error"], | ||
"prefer-const": ["error"], | ||
"no-var": ["error"], | ||
|
||
// Handling valid jsdoc. | ||
"jsdoc/check-access": "error", | ||
// Handled by prettier | ||
// "jsdoc/check-alignment": "error", | ||
"jsdoc/check-param-names": "error", | ||
"jsdoc/check-property-names": "error", | ||
"jsdoc/check-tag-names": "error", | ||
"jsdoc/check-types": "error", | ||
"jsdoc/empty-tags": "error", | ||
"jsdoc/tag-lines": ["error", "never", { startLines: 1 }], | ||
"jsdoc/no-multi-asterisks": "error", | ||
"jsdoc/require-param-type": "error", | ||
"jsdoc/require-returns-type": "error", | ||
"jsdoc/valid-types": "error", | ||
|
||
// Handling requiring jsdoc. | ||
"jsdoc/require-jsdoc": [ | ||
"error", | ||
{ | ||
require: { | ||
ClassDeclaration: true, | ||
FunctionDeclaration: false, | ||
}, | ||
}, | ||
], | ||
"jsdoc/require-param": "error", | ||
"jsdoc/require-param-description": "error", | ||
"jsdoc/require-param-name": "error", | ||
"jsdoc/require-property": "error", | ||
"jsdoc/require-property-description": "error", | ||
"jsdoc/require-property-name": "error", | ||
"jsdoc/require-property-type": "error", | ||
"jsdoc/require-returns": "error", | ||
"jsdoc/require-returns-check": "error", | ||
"jsdoc/require-yields": "error", | ||
"jsdoc/require-yields-check": "error", | ||
}, | ||
plugins: { | ||
jsdoc, | ||
}, | ||
}, | ||
|
||
// Should always be at the end, so that prettier is configured correctly. | ||
eslintConfigPrettier, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,36 @@ | ||
module.exports = { | ||
const { readFileSync } = require("fs"); | ||
|
||
const data = readFileSync("./package.json"); | ||
const packageJSON = JSON.parse(data); | ||
|
||
const plugin = { | ||
meta: { | ||
name: "eslint-plugin-no-unsanitized", | ||
version: packageJSON.version, | ||
}, | ||
rules: { | ||
property: require("./lib/rules/property"), | ||
method: require("./lib/rules/method"), | ||
}, | ||
configs: { | ||
DOM: { | ||
plugins: ["no-unsanitized"], | ||
rules: { | ||
"no-unsanitized/property": [ | ||
"error", | ||
{}, | ||
{ | ||
// Check unsafe assignment to innerHTML | ||
innerHTML: {}, | ||
|
||
// Check unsafe assignment to outerHTML | ||
outerHTML: {}, | ||
}, | ||
], | ||
"no-unsanitized/method": [ | ||
"error", | ||
{}, | ||
{ | ||
// check second parameter to .insertAdjacentHTML() | ||
insertAdjacentHTML: { | ||
properties: [1], | ||
}, | ||
configs: {}, | ||
}; | ||
|
||
// check first parameter to .write(), as long as the preceeding object matches the regex "document" | ||
write: { | ||
objectMatches: ["document"], | ||
properties: [0], | ||
}, | ||
const rules = { | ||
"no-unsanitized/property": "error", | ||
"no-unsanitized/method": "error", | ||
}; | ||
|
||
// check first parameter to .writeLn(), as long as the preceeding object matches the regex "document" | ||
writeln: { | ||
objectMatches: ["document"], | ||
properties: [0], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
Object.assign(plugin.configs, { | ||
"recommended-legacy": { | ||
plugins: ["no-unsanitized"], | ||
rules, | ||
}, | ||
}; | ||
recommended: [ | ||
{ | ||
plugins: { "no-unsanitized": plugin }, | ||
rules, | ||
}, | ||
], | ||
}); | ||
|
||
module.exports = plugin; |
Oops, something went wrong.