1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const report = require('../../utils/report');
|
6 | const ruleMessages = require('../../utils/ruleMessages');
|
7 | const validateOptions = require('../../utils/validateOptions');
|
8 |
|
9 | const ruleName = 'no-missing-end-of-source-newline';
|
10 |
|
11 | const messages = ruleMessages(ruleName, {
|
12 | rejected: 'Unexpected missing end-of-source newline',
|
13 | });
|
14 |
|
15 | function rule(primary, _, context) {
|
16 | return (root, result) => {
|
17 | const validOptions = validateOptions(result, ruleName, { primary });
|
18 |
|
19 | if (!validOptions) {
|
20 | return;
|
21 | }
|
22 |
|
23 | if (root.source.inline || root.source.lang === 'object-literal') {
|
24 | return;
|
25 | }
|
26 |
|
27 | const rootString = context.fix ? root.toString() : root.source.input.css;
|
28 |
|
29 | if (!rootString.trim() || rootString.endsWith('\n')) {
|
30 | return;
|
31 | }
|
32 |
|
33 |
|
34 | if (context.fix) {
|
35 | root.raws.after = context.newline;
|
36 |
|
37 | return;
|
38 | }
|
39 |
|
40 | report({
|
41 | message: messages.rejected,
|
42 | node: root,
|
43 | index: rootString.length - 1,
|
44 | result,
|
45 | ruleName,
|
46 | });
|
47 | };
|
48 | }
|
49 |
|
50 | rule.ruleName = ruleName;
|
51 | rule.messages = messages;
|
52 | module.exports = rule;
|