-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempty-first-line.js
39 lines (34 loc) · 1.08 KB
/
empty-first-line.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// https://eslint.org/docs/developer-guide/working-with-rules
// https://github.com/eslint/eslint/blob/master/lib/rules/eol-last.js
module.exports = {
meta: {
type: 'layout',
docs: {
description: 'require or disallow newline at the begining of files',
category: 'Stylistic Issues',
recommended: false,
},
fixable: 'whitespace',
schema: [{
// TODO: handle never option
enum: [ 'always', 'never' ],
}],
},
create(context) {
const sourceCode = context.getSourceCode();
const firstLine = sourceCode.lines[0];
return {
Program(node) {
if (firstLine.trim()) {
context.report({
node,
message: 'Newline required at begining of file but not found.',
fix(fixer) {
return fixer.insertTextAfterRange([ 0, 0 ], '\n');
},
});
}
},
};
},
};