Skip to content

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

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

Merged
merged 5 commits into from
Mar 19, 2024
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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