mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(linter): Added fixer for duplicate prefix in valid title jest rule (#6699)
This commit is contained in:
parent
01a35bb446
commit
5095f027e5
1 changed files with 54 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue