Skip to content

Commit

Permalink
support eslint v9 (#69)
Browse files Browse the repository at this point in the history
* support eslint v9

* test: make tests pass with eslint v9

* remove unneeded .eslintignore

* Add flat configurations
  • Loading branch information
anajavi authored Oct 18, 2024
1 parent 35e9912 commit e821d81
Show file tree
Hide file tree
Showing 10 changed files with 1,146 additions and 1,611 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ With this configuration, the "style" attribute is ignored for native elements fo

This plugin exports a `recommended` configuration that enforce React good practices.

### Flat configuration

To enable this configuration add the following to your eslint.config.js:
```js
import reactPerfPlugin from 'eslint-plugin-react-perf';

const config = [
reactPerfPlugin.configs.flat.recommended
];

export default config;
```

### eslintrc configuration

To enable this configuration use the `extends` property in your `.eslintrc` config file:

```js
Expand All @@ -78,6 +93,21 @@ The rules enabled in this configuration are:

This plugin also exports an `all` configuration that includes every available rule.

### Flat configuration

To enable this configuration add the following to your eslint.config.js:
```js
import reactPerfPlugin from 'eslint-plugin-react-perf';

const config = [
reactPerfPlugin.configs.flat.all
];

export default config;
```

### eslintrc configuration

```js
{
"plugins": [
Expand Down
26 changes: 26 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const js = require("@eslint/js");
const globals = require("globals");

const config = [
js.configs.recommended,
{
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
"space-before-function-paren": 0
},
},
{
files: ["tests/**/*.js"],
languageOptions: {
globals: {
...globals.mocha
}
}
}
];

module.exports = config;
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

var pkg = require('./package.json');

var allRules = {
"jsx-no-new-object-as-prop": require("./lib/rules/jsx-no-new-object-as-prop"),
"jsx-no-new-array-as-prop": require("./lib/rules/jsx-no-new-array-as-prop"),
Expand All @@ -18,7 +20,11 @@ function configureAsError(rules) {
return result;
}

module.exports = {
var plugin = {
meta: {
name: pkg.name,
version: pkg.version
},
rules: allRules,
configs: {
recommended: {
Expand All @@ -45,3 +51,18 @@ module.exports = {
}
}
};

plugin.configs.flat = {
recommended: {
plugins: { "react-perf": plugin },
rules: plugin.configs.recommended.rules,
languageOptions: { parserOptions: plugin.configs.recommended.parserOptions },
},
all: {
plugins: { "react-perf": plugin },
rules: plugin.configs.all.rules,
languageOptions: { parserOptions: plugin.configs.all.parserOptions },
},
};

module.exports = plugin;
7 changes: 6 additions & 1 deletion lib/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ function findRelevantNodes(context, node) {
return;
}
if (node.type === "Identifier") {
var variable = context.getScope().variables.find(function (variable) {
const sourceCode = context.sourceCode || context.getSourceCode();
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

var variable = scope.variables.find(function (variable) {
return variable.name === node.name;
});
if (variable) {
Expand Down
Loading

0 comments on commit e821d81

Please sign in to comment.