Skip to content

Commit d7f3de3

Browse files
macklinuSimenB
authored andcommittedMay 27, 2018
feat: add fixer for lowercase-name rule (#119)
Fixes #118
1 parent ca2d60b commit d7f3de3

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ for more information about extending configuration files.
8181
| Rule | Description | Recommended | Fixable |
8282
| ------------------------------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------ |
8383
| [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce consistent test or it keyword | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) |
84-
| [lowercase-name](docs/rules/lowercase-name.md) | Disallow capitalized test names | | |
84+
| [lowercase-name](docs/rules/lowercase-name.md) | Disallow capitalized test names | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) |
8585
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | |
8686
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | |
8787
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |

‎rules/__tests__/lowercase-name.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ ruleTester.run('lowercase-name', rule, {
2121
'it("<Foo/>", function () {})',
2222
'it("123 foo", function () {})',
2323
'it(42, function () {})',
24+
'it(``)',
2425
'test()',
2526
"test('foo', function () {})",
2627
'test("foo", function () {})',
2728
'test(`foo`, function () {})',
2829
'test("<Foo/>", function () {})',
2930
'test("123 foo", function () {})',
3031
'test("42", function () {})',
32+
'test(``)',
3133
'describe()',
3234
"describe('foo', function () {})",
3335
'describe("foo", function () {})',
@@ -36,11 +38,13 @@ ruleTester.run('lowercase-name', rule, {
3638
'describe("123 foo", function () {})',
3739
'describe("42", function () {})',
3840
'describe(function () {})',
41+
'describe(``)',
3942
],
4043

4144
invalid: [
4245
{
4346
code: "it('Foo', function () {})",
47+
output: "it('foo', function () {})",
4448
errors: [
4549
{
4650
message: '`it`s should begin with lowercase',
@@ -51,6 +55,7 @@ ruleTester.run('lowercase-name', rule, {
5155
},
5256
{
5357
code: 'it("Foo", function () {})',
58+
output: 'it("foo", function () {})',
5459
errors: [
5560
{
5661
message: '`it`s should begin with lowercase',
@@ -61,6 +66,7 @@ ruleTester.run('lowercase-name', rule, {
6166
},
6267
{
6368
code: 'it(`Foo`, function () {})',
69+
output: 'it(`foo`, function () {})',
6470
errors: [
6571
{
6672
message: '`it`s should begin with lowercase',
@@ -71,6 +77,7 @@ ruleTester.run('lowercase-name', rule, {
7177
},
7278
{
7379
code: "test('Foo', function () {})",
80+
output: "test('foo', function () {})",
7481
errors: [
7582
{
7683
message: '`test`s should begin with lowercase',
@@ -81,6 +88,7 @@ ruleTester.run('lowercase-name', rule, {
8188
},
8289
{
8390
code: 'test("Foo", function () {})',
91+
output: 'test("foo", function () {})',
8492
errors: [
8593
{
8694
message: '`test`s should begin with lowercase',
@@ -91,6 +99,7 @@ ruleTester.run('lowercase-name', rule, {
9199
},
92100
{
93101
code: 'test(`Foo`, function () {})',
102+
output: 'test(`foo`, function () {})',
94103
errors: [
95104
{
96105
message: '`test`s should begin with lowercase',
@@ -101,6 +110,7 @@ ruleTester.run('lowercase-name', rule, {
101110
},
102111
{
103112
code: "describe('Foo', function () {})",
113+
output: "describe('foo', function () {})",
104114
errors: [
105115
{
106116
message: '`describe`s should begin with lowercase',
@@ -111,6 +121,7 @@ ruleTester.run('lowercase-name', rule, {
111121
},
112122
{
113123
code: 'describe("Foo", function () {})',
124+
output: 'describe("foo", function () {})',
114125
errors: [
115126
{
116127
message: '`describe`s should begin with lowercase',
@@ -121,6 +132,18 @@ ruleTester.run('lowercase-name', rule, {
121132
},
122133
{
123134
code: 'describe(`Foo`, function () {})',
135+
output: 'describe(`foo`, function () {})',
136+
errors: [
137+
{
138+
message: '`describe`s should begin with lowercase',
139+
column: 1,
140+
line: 1,
141+
},
142+
],
143+
},
144+
{
145+
code: 'describe(`Some longer description`, function () {})',
146+
output: 'describe(`some longer description`, function () {})',
124147
errors: [
125148
{
126149
message: '`describe`s should begin with lowercase',

‎rules/lowercase-name.js

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
docs: {
5353
url: getDocsUrl(__filename),
5454
},
55+
fixable: 'code',
5556
},
5657
create(context) {
5758
const ignore = (context.options[0] && context.options[0].ignore) || [];
@@ -72,6 +73,22 @@ module.exports = {
7273
message: '`{{ method }}`s should begin with lowercase',
7374
data: { method: erroneousMethod },
7475
node,
76+
fix(fixer) {
77+
const firstArg = node.arguments[0];
78+
const description = testDescription(node);
79+
80+
const rangeIgnoringQuotes = [
81+
firstArg.start + 1,
82+
firstArg.end - 1,
83+
];
84+
const newDescription =
85+
description.substring(0, 1).toLowerCase() +
86+
description.substring(1);
87+
88+
return [
89+
fixer.replaceTextRange(rangeIgnoringQuotes, newDescription),
90+
];
91+
},
7592
});
7693
}
7794
},

0 commit comments

Comments
 (0)
Please sign in to comment.