From ba3a5c0c4a77308917754979cd439af95306e2d5 Mon Sep 17 00:00:00 2001 From: Nate Bailey Date: Sat, 11 Feb 2017 17:37:17 -0800 Subject: [PATCH] Fix broken tests, add docs --- docs/rules/newline-after-import.md | 40 +++++++++++++++++++++++-- tests/src/rules/newline-after-import.js | 6 ++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/rules/newline-after-import.md b/docs/rules/newline-after-import.md index 0ad2cba01..4c22a1861 100644 --- a/docs/rules/newline-after-import.md +++ b/docs/rules/newline-after-import.md @@ -1,9 +1,11 @@ # newline-after-import -Enforces having an empty line after the last top-level import statement or require call. +Enforces having one or more empty line after the last top-level import statement or require call. ## Rule Details +This rule has one option, `newlines` which sets the number of newlines that are enforced after the last top-level import statement or require call. This option defaults to `1`. + Valid: ```js @@ -26,7 +28,7 @@ const BAR = require('./bar') const BAZ = 1 ``` -...whereas here imports will be reported: +Invalid: ```js import * as foo from 'foo' @@ -46,6 +48,40 @@ const BAZ = 1 const BAR = require('./bar') ``` +With `newlines` set to `2` this will be considered valid: + +```js +import defaultExport from './foo' + + +const FOO = 'BAR' +``` + +With `newlines` set to `2` these will be considered invalid: + +```js +import defaultExport from './foo' +const FOO = 'BAR' +``` + +```js +import defaultExport from './foo' + +const FOO = 'BAR' +``` + + +## Example options usage +``` +{ + ... + "rules": { + "import/newline-after-import": [{ "newlines": 2 }] + } +} +``` + + ## When Not To Use It If you like to visually group module imports with its usage, you don't want to use this rule. diff --git a/tests/src/rules/newline-after-import.js b/tests/src/rules/newline-after-import.js index 8138c03a3..4f8773a6f 100644 --- a/tests/src/rules/newline-after-import.js +++ b/tests/src/rules/newline-after-import.js @@ -83,7 +83,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { { code: `import foo from 'foo';\n\n\nvar foo = 'bar';`, parserOptions: { sourceType: 'module' }, - options: { newlines: 2 }, + options: [{ 'newlines': 2 }], }, { code: `var foo = require('foo-module');\n\nvar foo = 'bar';`, @@ -92,7 +92,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { { code: `var foo = require('foo-module');\n\n\nvar foo = 'bar';`, parserOptions: { sourceType: 'module' }, - options: { newlines: 2 }, + options: [{ 'newlines': 2 }], }, { code: `require('foo-module');\n\nvar foo = 'bar';`, @@ -165,7 +165,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { }, { code: `import foo from 'foo';\n\nexport default function() {};`, - options: { newlines: 2 }, + options: [{ 'newlines': 2 }], errors: [ { line: 1, column: 1,