Skip to content
Permalink
Browse files
feat: add fixer for lowercase-name rule (#119)
Fixes #118
  • Loading branch information
macklinu authored and SimenB committed May 27, 2018
1 parent ca2d60b commit d7f3de3b0395b432034a1dcd1a1bbf67a35b57d9
Showing with 41 additions and 1 deletion.
  1. +1 −1 README.md
  2. +23 −0 rules/__tests__/lowercase-name.test.js
  3. +17 −0 rules/lowercase-name.js
@@ -81,7 +81,7 @@ for more information about extending configuration files.
| Rule | Description | Recommended | Fixable |
| ------------------------------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------ |
| [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce consistent test or it keyword | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) |
| [lowercase-name](docs/rules/lowercase-name.md) | Disallow capitalized test names | | |
| [lowercase-name](docs/rules/lowercase-name.md) | Disallow capitalized test names | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) |
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | |
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | |
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
@@ -21,13 +21,15 @@ ruleTester.run('lowercase-name', rule, {
'it("<Foo/>", function () {})',
'it("123 foo", function () {})',
'it(42, function () {})',
'it(``)',
'test()',
"test('foo', function () {})",
'test("foo", function () {})',
'test(`foo`, function () {})',
'test("<Foo/>", function () {})',
'test("123 foo", function () {})',
'test("42", function () {})',
'test(``)',
'describe()',
"describe('foo', function () {})",
'describe("foo", function () {})',
@@ -36,11 +38,13 @@ ruleTester.run('lowercase-name', rule, {
'describe("123 foo", function () {})',
'describe("42", function () {})',
'describe(function () {})',
'describe(``)',
],

invalid: [
{
code: "it('Foo', function () {})",
output: "it('foo', function () {})",
errors: [
{
message: '`it`s should begin with lowercase',
@@ -51,6 +55,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'it("Foo", function () {})',
output: 'it("foo", function () {})',
errors: [
{
message: '`it`s should begin with lowercase',
@@ -61,6 +66,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'it(`Foo`, function () {})',
output: 'it(`foo`, function () {})',
errors: [
{
message: '`it`s should begin with lowercase',
@@ -71,6 +77,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: "test('Foo', function () {})",
output: "test('foo', function () {})",
errors: [
{
message: '`test`s should begin with lowercase',
@@ -81,6 +88,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'test("Foo", function () {})',
output: 'test("foo", function () {})',
errors: [
{
message: '`test`s should begin with lowercase',
@@ -91,6 +99,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'test(`Foo`, function () {})',
output: 'test(`foo`, function () {})',
errors: [
{
message: '`test`s should begin with lowercase',
@@ -101,6 +110,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: "describe('Foo', function () {})",
output: "describe('foo', function () {})",
errors: [
{
message: '`describe`s should begin with lowercase',
@@ -111,6 +121,7 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'describe("Foo", function () {})',
output: 'describe("foo", function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
@@ -121,6 +132,18 @@ ruleTester.run('lowercase-name', rule, {
},
{
code: 'describe(`Foo`, function () {})',
output: 'describe(`foo`, function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
column: 1,
line: 1,
},
],
},
{
code: 'describe(`Some longer description`, function () {})',
output: 'describe(`some longer description`, function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
@@ -52,6 +52,7 @@ module.exports = {
docs: {
url: getDocsUrl(__filename),
},
fixable: 'code',
},
create(context) {
const ignore = (context.options[0] && context.options[0].ignore) || [];
@@ -72,6 +73,22 @@ module.exports = {
message: '`{{ method }}`s should begin with lowercase',
data: { method: erroneousMethod },
node,
fix(fixer) {
const firstArg = node.arguments[0];
const description = testDescription(node);

const rangeIgnoringQuotes = [
firstArg.start + 1,
firstArg.end - 1,
];
const newDescription =
description.substring(0, 1).toLowerCase() +
description.substring(1);

return [
fixer.replaceTextRange(rangeIgnoringQuotes, newDescription),
];
},
});
}
},

0 comments on commit d7f3de3

Please sign in to comment.