Skip to content

Commit 5095f02

Browse files
authoredOct 20, 2024··
feat(linter): Added fixer for duplicate prefix in valid title jest rule (#6699)
1 parent 01a35bb commit 5095f02

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed
 

‎crates/oxc_linter/src/rules/jest/valid_title.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,12 @@ fn validate_title(
312312
return;
313313
};
314314

315-
// TODO: support fixer
316315
if first_word == un_prefixed_name {
317-
Message::DuplicatePrefix.diagnostic(ctx, span);
316+
let (error, help) = Message::DuplicatePrefix.detail();
317+
ctx.diagnostic_with_fix(valid_title_diagnostic(error, help, span), |fixer| {
318+
let replaced_title = title[first_word.len()..].trim().to_string();
319+
fixer.replace(span.shrink_left(1).shrink_right(1), replaced_title)
320+
});
318321
return;
319322
}
320323

@@ -967,6 +970,55 @@ fn test() {
967970
})
968971
",
969972
),
973+
("describe('describe foo', function () {})", "describe('foo', function () {})"),
974+
("fdescribe('describe foo', function () {})", "fdescribe('foo', function () {})"),
975+
("xdescribe('describe foo', function () {})", "xdescribe('foo', function () {})"),
976+
("describe('describe foo', function () {})", "describe('foo', function () {})"),
977+
("fdescribe(`describe foo`, function () {})", "fdescribe(`foo`, function () {})"),
978+
("test('test foo', function () {})", "test('foo', function () {})"),
979+
("xtest('test foo', function () {})", "xtest('foo', function () {})"),
980+
("test(`test foo`, function () {})", "test(`foo`, function () {})"),
981+
("test(`test foo test`, function () {})", "test(`foo test`, function () {})"),
982+
("it('it foo', function () {})", "it('foo', function () {})"),
983+
("fit('it foo', function () {})", "fit('foo', function () {})"),
984+
("xit('it foo', function () {})", "xit('foo', function () {})"),
985+
("it('it foos it correctly', function () {})", "it('foos it correctly', function () {})"),
986+
(
987+
"
988+
describe('describe foo', () => {
989+
it('bar', () => {})
990+
})
991+
",
992+
"
993+
describe('foo', () => {
994+
it('bar', () => {})
995+
})
996+
",
997+
),
998+
(
999+
"
1000+
describe('describe foo', () => {
1001+
it('describes things correctly', () => {})
1002+
})
1003+
",
1004+
"
1005+
describe('foo', () => {
1006+
it('describes things correctly', () => {})
1007+
})
1008+
",
1009+
),
1010+
(
1011+
"
1012+
describe('foo', () => {
1013+
it('it bar', () => {})
1014+
})
1015+
",
1016+
"
1017+
describe('foo', () => {
1018+
it('bar', () => {})
1019+
})
1020+
",
1021+
),
9701022
];
9711023

9721024
Tester::new(ValidTitle::NAME, pass, fail)

0 commit comments

Comments
 (0)
Please sign in to comment.