Skip to content
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

fix(eslint-plugin): [member-delimiter-style] autofixer result is not as expected with option delimiter: 'none' #5023

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/member-delimiter-style.ts
Expand Up @@ -68,8 +68,8 @@ const definition = {
additionalProperties: false,
};

const isLastTokenEndOfLine = (token: string, line: string): boolean => {
const positionInLine = line.indexOf(token);
const isLastTokenEndOfLine = (token: LastTokenType, line: string): boolean => {
const positionInLine = token.loc.start.column;

return positionInLine === line.length - 1;
};
Expand All @@ -85,7 +85,7 @@ const makeFixFunction = ({
// if removing is the action but last token is not the end of the line
if (
optsNone &&
!isLastTokenEndOfLine(lastToken.value, lastTokenLine) &&
!isLastTokenEndOfLine(lastToken, lastTokenLine) &&
!isSingleLine
) {
return null;
Expand Down
38 changes: 38 additions & 0 deletions packages/eslint-plugin/tests/rules/member-delimiter-style.test.ts
Expand Up @@ -3548,5 +3548,43 @@ type Foo = {a: {
},
],
},
{
code: `
type Foo = {
a: {
b: true;
}; c: false;
}
`,
output: `
type Foo = {
a: {
b: true
}; c: false
}
`,
options: [
{
multiline: { delimiter: 'none' },
},
],
errors: [
{
messageId: 'unexpectedSemi',
line: 4,
column: 13,
},
{
messageId: 'unexpectedSemi',
line: 5,
column: 5,
},
{
messageId: 'unexpectedSemi',
line: 5,
column: 15,
},
],
},
],
});