Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-empty-interface] disable autofix for declaration merging with class#5920

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 5 commits intotypescript-eslint:mainfromyeonjuan:fix/#5273
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
31 changes: 21 additions & 10 deletionspackages/eslint-plugin/src/rules/no-empty-interface.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import type { TSESLint } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import * as util from '../util';

Expand DownExpand Up@@ -73,29 +74,39 @@ export default util.createRule<Options, MessageIds>({
)}${typeParam} = ${sourceCode.getText(extend[0])}`,
);
};
const scope = context.getScope();

// Check if interface is within ambient declaration
let useAutoFix = true;
if (util.isDefinitionFile(filename)) {
const scope = context.getScope();
if (scope.type === 'tsModule' && scope.block.declare) {
useAutoFix = false;
}
}
const mergedWithClassDeclaration = scope.set
.get(node.id.name)
?.defs?.some(
def => def.node.type === AST_NODE_TYPES.ClassDeclaration,
);

const isInAmbientDeclaration = !!(
util.isDefinitionFile(filename) &&
scope.type === 'tsModule' &&
scope.block.declare
);

const useAutoFix = !(
isInAmbientDeclaration || mergedWithClassDeclaration
);

context.report({
node: node.id,
messageId: 'noEmptyWithSuper',
...(useAutoFix
? { fix }
: {
: !mergedWithClassDeclaration
? {
suggest: [
{
messageId: 'noEmptyWithSuper',
fix,
},
],
}),
}
: null),
});
}
}
Expand Down
88 changes: 88 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-empty-interface.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,18 @@ interface Bar extends Foo {}
`,
options: [{ allowSingleExtends: true }],
},
{
code: `
interface Foo {
props: string;
}

interface Bar extends Foo {}

class Bar {}
`,
options: [{ allowSingleExtends: true }],
},
],
invalid: [
{
Expand All@@ -58,6 +70,82 @@ interface Bar extends Foo {}
},
{
code: `
interface Foo {
props: string;
}

interface Bar extends Foo {}

class Baz {}
`,
output: `
interface Foo {
props: string;
}

type Bar = Foo

class Baz {}
`,
options: [{ allowSingleExtends: false }],
errors: [
{
messageId: 'noEmptyWithSuper',
line: 6,
column: 11,
},
],
},
{
code: `
interface Foo {
props: string;
}

interface Bar extends Foo {}

class Bar {}
`,
options: [{ allowSingleExtends: false }],
errors: [
{
messageId: 'noEmptyWithSuper',
line: 6,
column: 11,
},
],
output: null,
},
{
code: `
interface Foo {
props: string;
}

interface Bar extends Foo {}

const bar = class Bar {};
`,
output: `
interface Foo {
props: string;
}

type Bar = Foo

const bar = class Bar {};
`,
options: [{ allowSingleExtends: false }],
errors: [
{
messageId: 'noEmptyWithSuper',
line: 6,
column: 11,
},
],
},
{
code: `
interface Foo {
name: string;
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp