Skip to content

Commit

Permalink
Upgrade to & supoport ESlint v9 (fixes #234) (#239)
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
Standard8 authored May 14, 2024
1 parent ea2f6de commit d9704a7
Show file tree
Hide file tree
Showing 12 changed files with 693 additions and 456 deletions.
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
eslint-version: [8.x, 7.x, 6.x]
node-version: [16.x, 14.x]
eslint-version: [9.x, 8.x]
node-version: [20.x, 18.x]
steps:
- uses: actions/checkout@v2

Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,38 @@ $ npm install --save-dev eslint-plugin-no-unsanitized

## Usage

### Flat config

```js
import nounsanitized from "eslint-plugin-no-unsanitized";

export default config = [nounsanitized.configs.recommended];
```

or

```js
import nounsanitized from "eslint-plugin-no-unsanitized";

export default config = [
{
files: ["**/*.js"],
plugins: { nounsanitized },
rules: {
"no-unsanitized/method": "error",
"no-unsanitized/property": "error",
},
},
];
```

### eslintrc

In your `.eslintrc.json` file enable this rule with the following:

```json
{
"extends": ["plugin:no-unsanitized/DOM"]
"extends": ["plugin:no-unsanitized/recommended-legacy"]
}
```

Expand Down
78 changes: 78 additions & 0 deletions eslint.config.mjs
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,
];
68 changes: 29 additions & 39 deletions index.js
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;
Loading

0 comments on commit d9704a7

Please sign in to comment.