mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(linter): Add title whitespace fixer for jest valid title rule (#6669)
Supported fixer for white space in title for valid title rule. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
45f02d5a41
commit
e9976d46d4
1 changed files with 86 additions and 5 deletions
|
|
@ -67,7 +67,8 @@ declare_oxc_lint!(
|
|||
/// xtest('', () => {});
|
||||
/// ```
|
||||
ValidTitle,
|
||||
correctness
|
||||
correctness,
|
||||
conditional_fix
|
||||
);
|
||||
|
||||
impl Rule for ValidTitle {
|
||||
|
|
@ -297,9 +298,13 @@ fn validate_title(
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: support fixer
|
||||
if !valid_title.ignore_space && title.trim() != title {
|
||||
Message::AccidentalSpace.diagnostic(ctx, span);
|
||||
let trimmed_title = title.trim();
|
||||
if !valid_title.ignore_space && trimmed_title != title {
|
||||
let (error, help) = Message::AccidentalSpace.detail();
|
||||
ctx.diagnostic_with_fix(valid_title_diagnostic(error, help, span), |fixer| {
|
||||
let target_span = Span::new(span.start + 1, span.end - 1);
|
||||
fixer.replace(target_span, trimmed_title.to_string())
|
||||
});
|
||||
}
|
||||
|
||||
let un_prefixed_name = name.trim_start_matches(['f', 'x']);
|
||||
|
|
@ -891,5 +896,81 @@ fn test() {
|
|||
),
|
||||
];
|
||||
|
||||
Tester::new(ValidTitle::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
|
||||
let fix = vec![
|
||||
("describe(' foo', function () {})", "describe('foo', function () {})"),
|
||||
("describe.each()(' foo', function () {})", "describe.each()('foo', function () {})"),
|
||||
(
|
||||
"describe.only.each()(' foo', function () {})",
|
||||
"describe.only.each()('foo', function () {})",
|
||||
),
|
||||
("describe(' foo foe fum', function () {})", "describe('foo foe fum', function () {})"),
|
||||
("describe('foo foe fum ', function () {})", "describe('foo foe fum', function () {})"),
|
||||
("fdescribe(' foo', function () {})", "fdescribe('foo', function () {})"),
|
||||
("fdescribe(' foo', function () {})", "fdescribe('foo', function () {})"),
|
||||
("xdescribe(' foo', function () {})", "xdescribe('foo', function () {})"),
|
||||
("it(' foo', function () {})", "it('foo', function () {})"),
|
||||
("it.concurrent(' foo', function () {})", "it.concurrent('foo', function () {})"),
|
||||
("fit(' foo', function () {})", "fit('foo', function () {})"),
|
||||
("it.skip(' foo', function () {})", "it.skip('foo', function () {})"),
|
||||
("fit('foo ', function () {})", "fit('foo', function () {})"),
|
||||
("it.skip('foo ', function () {})", "it.skip('foo', function () {})"),
|
||||
(
|
||||
"
|
||||
import { test as testThat } from '@jest/globals';
|
||||
|
||||
testThat('foo works ', () => {});
|
||||
",
|
||||
"
|
||||
import { test as testThat } from '@jest/globals';
|
||||
|
||||
testThat('foo works', () => {});
|
||||
",
|
||||
),
|
||||
("xit(' foo', function () {})", "xit('foo', function () {})"),
|
||||
("test(' foo', function () {})", "test('foo', function () {})"),
|
||||
("test.concurrent(' foo', function () {})", "test.concurrent('foo', function () {})"),
|
||||
("test(` foo`, function () {})", "test(`foo`, function () {})"),
|
||||
("test.concurrent(` foo`, function () {})", "test.concurrent(`foo`, function () {})"),
|
||||
("test(` foo bar bang`, function () {})", "test(`foo bar bang`, function () {})"),
|
||||
(
|
||||
"test.concurrent(` foo bar bang`, function () {})",
|
||||
"test.concurrent(`foo bar bang`, function () {})",
|
||||
),
|
||||
("test(` foo bar bang `, function () {})", "test(`foo bar bang`, function () {})"),
|
||||
(
|
||||
"test.concurrent(` foo bar bang `, function () {})",
|
||||
"test.concurrent(`foo bar bang`, function () {})",
|
||||
),
|
||||
("xtest(' foo', function () {})", "xtest('foo', function () {})"),
|
||||
("xtest(' foo ', function () {})", "xtest('foo', function () {})"),
|
||||
(
|
||||
"
|
||||
describe(' foo', () => {
|
||||
it('bar', () => {})
|
||||
})
|
||||
",
|
||||
"
|
||||
describe('foo', () => {
|
||||
it('bar', () => {})
|
||||
})
|
||||
",
|
||||
),
|
||||
(
|
||||
"
|
||||
describe('foo', () => {
|
||||
it(' bar', () => {})
|
||||
})
|
||||
",
|
||||
"
|
||||
describe('foo', () => {
|
||||
it('bar', () => {})
|
||||
})
|
||||
",
|
||||
),
|
||||
];
|
||||
|
||||
Tester::new(ValidTitle::NAME, pass, fail)
|
||||
.with_jest_plugin(true)
|
||||
.expect_fix(fix)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue