Skip to content

Commit

Permalink
feat(linter): Added fixer for duplicate prefix in valid title jest ru…
Browse files Browse the repository at this point in the history
…le (#6699)
  • Loading branch information
tapanprakasht authored Oct 20, 2024
1 parent 01a35bb commit 5095f02
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions crates/oxc_linter/src/rules/jest/valid_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ fn validate_title(
return;
};

// TODO: support fixer
if first_word == un_prefixed_name {
Message::DuplicatePrefix.diagnostic(ctx, span);
let (error, help) = Message::DuplicatePrefix.detail();
ctx.diagnostic_with_fix(valid_title_diagnostic(error, help, span), |fixer| {
let replaced_title = title[first_word.len()..].trim().to_string();
fixer.replace(span.shrink_left(1).shrink_right(1), replaced_title)
});
return;
}

Expand Down Expand Up @@ -967,6 +970,55 @@ fn test() {
})
",
),
("describe('describe foo', function () {})", "describe('foo', function () {})"),
("fdescribe('describe foo', function () {})", "fdescribe('foo', function () {})"),
("xdescribe('describe foo', function () {})", "xdescribe('foo', function () {})"),
("describe('describe foo', function () {})", "describe('foo', function () {})"),
("fdescribe(`describe foo`, function () {})", "fdescribe(`foo`, function () {})"),
("test('test foo', function () {})", "test('foo', function () {})"),
("xtest('test foo', function () {})", "xtest('foo', function () {})"),
("test(`test foo`, function () {})", "test(`foo`, function () {})"),
("test(`test foo test`, function () {})", "test(`foo test`, function () {})"),
("it('it foo', function () {})", "it('foo', function () {})"),
("fit('it foo', function () {})", "fit('foo', function () {})"),
("xit('it foo', function () {})", "xit('foo', function () {})"),
("it('it foos it correctly', function () {})", "it('foos it correctly', function () {})"),
(
"
describe('describe foo', () => {
it('bar', () => {})
})
",
"
describe('foo', () => {
it('bar', () => {})
})
",
),
(
"
describe('describe foo', () => {
it('describes things correctly', () => {})
})
",
"
describe('foo', () => {
it('describes things correctly', () => {})
})
",
),
(
"
describe('foo', () => {
it('it bar', () => {})
})
",
"
describe('foo', () => {
it('bar', () => {})
})
",
),
];

Tester::new(ValidTitle::NAME, pass, fail)
Expand Down

0 comments on commit 5095f02

Please sign in to comment.