Skip to content

Commit

Permalink
code refactoring + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pri1311 committed Mar 29, 2022
1 parent 9d64c39 commit a1cfdc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 1 addition & 14 deletions src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,7 @@ module.exports = {
create(context) {
let level = 0;
const requireCalls = [];
const options = setOptions(context);

function setOptions(context) {
if (context.options[0]) {
if ('count' in context.options[0] && 'considerComments' in context.options[0] ) {
return context.options[0];
} else if ( 'count' in context.options[0] ) {
return Object.assign({}, context.options[0], { considerComments: false });
} else {
return Object.assign({}, context.options[0], { count: 1 });
}
}
return { count: 1, considerComments: false };
}
const options = Object.assign({ count: 1, considerComments: false }, context.options[0]);

function checkForNewLine(node, nextNode, type) {
if (isExportDefaultClass(nextNode) || isExportNameClass(nextNode)) {
Expand Down
11 changes: 11 additions & 0 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
`,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' } ,
},
{
code: `
import { A, B, C, D } from
'../path/to/my/module/in/very/far/directory'
// some comment
var foo = 'bar';
`,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
options: [{ 'considerComments': true }],
},
),

invalid: [].concat(
Expand Down

0 comments on commit a1cfdc3

Please sign in to comment.