Skip to content

Commit

Permalink
fix: false positives in 5.4.0 for functions that aren't ESLint rules (#…
Browse files Browse the repository at this point in the history
…451)

* fix: false positives in 5.4.0 for functions that aren't ESLint rules

fixes #450

* fix: ignore fixtures

* fix: use pathIgnorePattern

* chore: upgrade eslint-doc-generator

* refactor: nodes decl
  • Loading branch information
aladdin-add committed Mar 19, 2024
1 parent 8a6f148 commit f3ec88e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -79,8 +79,8 @@ module.exports = [
💼 [Configurations](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets) enabled in.\
✅ Set in the `recommended` [configuration](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets).\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).\
💭 Requires type information.
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting).

### Rules

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-only-tests.md
Expand Up @@ -2,7 +2,7 @@

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets).

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-property-in-node.md
@@ -1,6 +1,6 @@
# Disallow using `in` to narrow node types instead of looking at properties (`eslint-plugin/no-property-in-node`)

💭 This rule requires type information.
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/require-meta-schema.md
Expand Up @@ -2,7 +2,7 @@

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets).

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

Expand Down
5 changes: 4 additions & 1 deletion eslint-remote-tester.config.js
Expand Up @@ -41,10 +41,13 @@ module.exports = {
/** Optional boolean flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching. Defaults to true. */
cache: false,

pathIgnorePattern: 'fixtures',

/** ESLint configuration */
eslintrc: {
root: true,
extends: ['plugin:eslint-plugin/all'],

// ignorePatterns: ['fixtures/**/*'], // not working somehow - using `pathIgnorePattern` as of now.
overrides: [
{
files: ['*.ts', '*.mts', '*.cts'],
Expand Down
27 changes: 18 additions & 9 deletions lib/utils.js
Expand Up @@ -139,15 +139,24 @@ function getRuleExportsESM(ast, scopeManager) {
possibleNodes.push(specifier.local);
}
if (statement.declaration) {
if (statement.declaration.type === 'VariableDeclaration') {
for (const declarator of statement.declaration.declarations) {
if (declarator.init) {
possibleNodes.push(declarator.init);
}
}
} else {
possibleNodes.push(statement.declaration);
}
const nodes =
statement.declaration.type === 'VariableDeclaration'
? statement.declaration.declarations.map(
(declarator) => declarator.init
)
: [statement.declaration];

// named exports like `export const rule = { ... };`
// skip if it's function-style to avoid false positives
// refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
possibleNodes.push(
...nodes.filter(
(node) =>
node &&
node.type !== 'FunctionDeclaration' &&
node.type !== 'FunctionExpression'
)
);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -64,14 +64,14 @@
"eslint": "^8.23.0",
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-doc-generator": "^1.6.1",
"eslint-doc-generator": "^1.7.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "file:./",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^46.0.0",
"eslint-remote-tester": "^3.0.0",
"eslint-remote-tester": "^3.0.1",
"eslint-scope": "^7.1.1",
"espree": "^9.4.0",
"globals": "^13.20.0",
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/utils.js
Expand Up @@ -86,6 +86,14 @@ describe('utils', () => {
'export default function () { return {}; }',
'export default function (foo, bar) { return {}; }',

// named export of functions
// refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
'export function foo(options) { return {}; }',
'export async function foo(options) { return {}; }',
'export const foo = function (options) { return {}; }',
'export function foo(options) { return; }',
'export function foo({opt1, opt2}) { return {}; }',

// Incorrect TypeScript helper structure:
'export default foo()({ create() {}, meta: {} });',
'export default foo().bar({ create() {}, meta: {} });',
Expand Down

0 comments on commit f3ec88e

Please sign in to comment.