This rule enforces having exactly one newline at the beginning of a file before the first import. This is purely for aesthetic reasons, as it makes the file easier to read by giving it some padding. Newlines at the end of the file are governed by the eol-last
rule which should be configured separately.
1 import foo from 'foo'
2 import bar from 'bar'
1
2 import foo from 'foo'
3 import bar from 'bar'
The rule accepts one argument:
always
(default) - requires a newline at the beginning of the filenever
- disallows a newline at the beginning of the file
{
'@nolawnchairs/first-newline': [
'error',
'always',
]
}
Some files require the first line to hold data, such as a binary script:
#!/usr/bin/env node
console.log('Hello, Newman')
Or with a string directive such as "use strict"
:
'use strict'
console.log('Hello, Newman')
This rule accounts for these cases and will forbid a beginning newline and will always require a newline after the first line, regardless of the configuration.