-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add count
option to newline-after-import
#742
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
14605f8
Add `newlines` option to `newline-after-import`
ntdb 3e5acab
Add tests for `newline-after-import` option and fix linter errors in …
ntdb ba3a5c0
Fix broken tests, add docs
ntdb 8c7ea26
Update CHANGELOG
ntdb 1d757dc
Add schema and further testing for `newlines` option on `newline-afte…
ntdb c0f733b
Change `newlines` option to `count` for `newline-after-import` rule
ntdb 2323ece
Fix missing plural in docs
ntdb 639c227
Add links in changelog and thank @ntdb :)
jfmengels 49ea883
Add links to rules in changelog
jfmengels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ const ruleTester = new RuleTester() | |
|
||
ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | ||
valid: [ | ||
"var path = require('path');\nvar foo = require('foo');\n", | ||
"require('foo');", | ||
"switch ('foo') { case 'bar': require('baz'); }", | ||
`var path = require('path');\nvar foo = require('foo');\n`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind changing this to backticks, but then we might as well replace the |
||
`require('foo');`, | ||
`switch ('foo') { case 'bar': require('baz'); }`, | ||
{ | ||
code: ` | ||
const x = () => require('baz') | ||
|
@@ -20,8 +20,8 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
code: `const x = () => require('baz') && require('bar')`, | ||
parserOptions: { ecmaVersion: 6 } , | ||
}, | ||
"function x(){ require('baz'); }", | ||
"a(require('b'), require('c'), require('d'));", | ||
`function x(){ require('baz'); }`, | ||
`a(require('b'), require('c'), require('d'));`, | ||
`function foo() { | ||
switch (renderData.modalViewKey) { | ||
case 'value': | ||
|
@@ -65,40 +65,60 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import path from 'path';\nimport foo from 'foo';\n", | ||
code: `import path from 'path';\nimport foo from 'foo';\n`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import path from 'path';import foo from 'foo';\n", | ||
code: `import path from 'path';import foo from 'foo';\n`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import path from 'path';import foo from 'foo';\n\nvar bar = 42;", | ||
code: `import path from 'path';import foo from 'foo';\n\nvar bar = 42;`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import foo from 'foo';\n\nvar foo = 'bar';", | ||
parserOptions: { sourceType: 'module' } | ||
code: `import foo from 'foo';\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: `import foo from 'foo';\n\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
options: [{ 'count': 2 }], | ||
}, | ||
{ | ||
code: `import foo from 'foo';\n\n\n\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
options: [{ 'count': 4 }], | ||
}, | ||
{ | ||
code: `var foo = require('foo-module');\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: `var foo = require('foo-module');\n\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
options: [{ 'count': 2 }], | ||
}, | ||
{ | ||
code: "var foo = require('foo-module');\n\nvar foo = 'bar';", | ||
parserOptions: { sourceType: 'module' } | ||
code: `var foo = require('foo-module');\n\n\n\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
options: [{ 'count': 4 }], | ||
}, | ||
{ | ||
code: "require('foo-module');\n\nvar foo = 'bar';", | ||
parserOptions: { sourceType: 'module' } | ||
code: `require('foo-module');\n\nvar foo = 'bar';`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import foo from 'foo';\nimport { bar } from './bar-lib';", | ||
parserOptions: { sourceType: 'module' } | ||
code: `import foo from 'foo';\nimport { bar } from './bar-lib';`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import foo from 'foo';\n\nvar a = 123;\n\nimport { bar } from './bar-lib';", | ||
parserOptions: { sourceType: 'module' } | ||
code: `import foo from 'foo';\n\nvar a = 123;\n\nimport { bar } from './bar-lib';`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "var foo = require('foo-module');\n\nvar a = 123;\n\nvar bar = require('bar-lib');", | ||
parserOptions: { sourceType: 'module' } | ||
code: `var foo = require('foo-module');\n\nvar a = 123;\n\nvar bar = require('bar-lib');`, | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: ` | ||
|
@@ -137,114 +157,134 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
parser: 'babel-eslint', | ||
}, | ||
{ | ||
code: "var foo = require('foo');\n\n@SomeDecorator(foo)\nclass Foo {}", | ||
code: `var foo = require('foo');\n\n@SomeDecorator(foo)\nclass Foo {}`, | ||
parserOptions: { sourceType: 'module' }, | ||
parser: 'babel-eslint', | ||
}, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "import foo from 'foo';\nexport default function() {};", | ||
code: `import foo from 'foo';\nexport default function() {};`, | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
message: IMPORT_ERROR_MESSAGE | ||
message: IMPORT_ERROR_MESSAGE, | ||
} ], | ||
parserOptions: { sourceType: 'module' } | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "var foo = require('foo-module');\nvar something = 123;", | ||
code: `import foo from 'foo';\n\nexport default function() {};`, | ||
options: [{ 'count': 2 }], | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: IMPORT_ERROR_MESSAGE, | ||
} ], | ||
parserOptions: { sourceType: 'module' } | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import foo from 'foo';\nvar a = 123;\n\nimport { bar } from './bar-lib';\nvar b=456;", | ||
code: `import foo from 'foo';\nexport default function() {};`, | ||
options: [{ 'count': 1 }], | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
message: IMPORT_ERROR_MESSAGE, | ||
} ], | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: `var foo = require('foo-module');\nvar something = 123;`, | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE, | ||
} ], | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: `import foo from 'foo';\nvar a = 123;\n\nimport { bar } from './bar-lib';\nvar b=456;`, | ||
errors: [ | ||
{ | ||
line: 1, | ||
column: 1, | ||
message: IMPORT_ERROR_MESSAGE | ||
message: IMPORT_ERROR_MESSAGE, | ||
}, | ||
{ | ||
line: 4, | ||
column: 1, | ||
message: IMPORT_ERROR_MESSAGE | ||
message: IMPORT_ERROR_MESSAGE, | ||
}], | ||
parserOptions: { sourceType: 'module' } | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "var foo = require('foo-module');\nvar a = 123;\n\nvar bar = require('bar-lib');\nvar b=456;", | ||
code: `var foo = require('foo-module');\nvar a = 123;\n\nvar bar = require('bar-lib');\nvar b=456;`, | ||
errors: [ | ||
{ | ||
line: 1, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}, | ||
{ | ||
line: 4, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}], | ||
parserOptions: { sourceType: 'module' } | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "var foo = require('foo-module');\nvar a = 123;\n\nrequire('bar-lib');\nvar b=456;", | ||
code: `var foo = require('foo-module');\nvar a = 123;\n\nrequire('bar-lib');\nvar b=456;`, | ||
errors: [ | ||
{ | ||
line: 1, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}, | ||
{ | ||
line: 4, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}], | ||
parserOptions: { sourceType: 'module' } | ||
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "var path = require('path');\nvar foo = require('foo');\nvar bar = 42;", | ||
code: `var path = require('path');\nvar foo = require('foo');\nvar bar = 42;`, | ||
errors: [ { | ||
line: 2, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE, | ||
} ] | ||
} ], | ||
}, | ||
{ | ||
code: "var assign = Object.assign || require('object-assign');\nvar foo = require('foo');\nvar bar = 42;", | ||
code: `var assign = Object.assign || require('object-assign');\nvar foo = require('foo');\nvar bar = 42;`, | ||
errors: [ { | ||
line: 2, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE, | ||
} ] | ||
} ], | ||
}, | ||
{ | ||
code: "require('a');\nfoo(require('b'), require('c'), require('d'));\nrequire('d');\nvar foo = 'bar';", | ||
code: `require('a');\nfoo(require('b'), require('c'), require('d'));\nrequire('d');\nvar foo = 'bar';`, | ||
errors: [ | ||
{ | ||
line: 3, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}, | ||
] | ||
], | ||
}, | ||
{ | ||
code: "require('a');\nfoo(\nrequire('b'),\nrequire('c'),\nrequire('d')\n);\nvar foo = 'bar';", | ||
code: `require('a');\nfoo(\nrequire('b'),\nrequire('c'),\nrequire('d')\n);\nvar foo = 'bar';`, | ||
errors: [ | ||
{ | ||
line: 6, | ||
column: 1, | ||
message: REQUIRE_ERROR_MESSAGE | ||
} | ||
] | ||
message: REQUIRE_ERROR_MESSAGE, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "import path from 'path';\nimport foo from 'foo';\nvar bar = 42;", | ||
code: `import path from 'path';\nimport foo from 'foo';\nvar bar = 42;`, | ||
errors: [ { | ||
line: 2, | ||
column: 1, | ||
|
@@ -253,7 +293,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import path from 'path';import foo from 'foo';var bar = 42;", | ||
code: `import path from 'path';import foo from 'foo';var bar = 42;`, | ||
errors: [ { | ||
line: 1, | ||
column: 25, | ||
|
@@ -262,7 +302,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
parserOptions: { sourceType: 'module' }, | ||
}, | ||
{ | ||
code: "import foo from 'foo';\n@SomeDecorator(foo)\nclass Foo {}", | ||
code: `import foo from 'foo';\n@SomeDecorator(foo)\nclass Foo {}`, | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
|
@@ -272,7 +312,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { | |
parser: 'babel-eslint', | ||
}, | ||
{ | ||
code: "var foo = require('foo');\n@SomeDecorator(foo)\nclass Foo {}", | ||
code: `var foo = require('foo');\n@SomeDecorator(foo)\nclass Foo {}`, | ||
errors: [ { | ||
line: 1, | ||
column: 1, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert all the changes to this file, except for your addition of course