1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const hasBlock = require('../../utils/hasBlock');
|
6 | const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
|
7 | const nextNonCommentNode = require('../../utils/nextNonCommentNode');
|
8 | const rawNodeString = require('../../utils/rawNodeString');
|
9 | const report = require('../../utils/report');
|
10 | const ruleMessages = require('../../utils/ruleMessages');
|
11 | const validateOptions = require('../../utils/validateOptions');
|
12 | const whitespaceChecker = require('../../utils/whitespaceChecker');
|
13 |
|
14 | const ruleName = 'at-rule-semicolon-newline-after';
|
15 |
|
16 | const messages = ruleMessages(ruleName, {
|
17 | expectedAfter: () => 'Expected newline after ";"',
|
18 | });
|
19 |
|
20 | function rule(actual, secondary, context) {
|
21 | const checker = whitespaceChecker('newline', actual, messages);
|
22 |
|
23 | return (root, result) => {
|
24 | const validOptions = validateOptions(result, ruleName, {
|
25 | actual,
|
26 | possible: ['always'],
|
27 | });
|
28 |
|
29 | if (!validOptions) {
|
30 | return;
|
31 | }
|
32 |
|
33 | root.walkAtRules((atRule) => {
|
34 | const nextNode = atRule.next();
|
35 |
|
36 | if (!nextNode) {
|
37 | return;
|
38 | }
|
39 |
|
40 | if (hasBlock(atRule)) {
|
41 | return;
|
42 | }
|
43 |
|
44 | if (!isStandardSyntaxAtRule(atRule)) {
|
45 | return;
|
46 | }
|
47 |
|
48 |
|
49 | const nodeToCheck = nextNonCommentNode(nextNode);
|
50 |
|
51 | if (!nodeToCheck) {
|
52 | return;
|
53 | }
|
54 |
|
55 | checker.afterOneOnly({
|
56 | source: rawNodeString(nodeToCheck),
|
57 | index: -1,
|
58 | err: (msg) => {
|
59 | if (context.fix) {
|
60 | nodeToCheck.raws.before = context.newline + nodeToCheck.raws.before;
|
61 | } else {
|
62 | report({
|
63 | message: msg,
|
64 | node: atRule,
|
65 | index: atRule.toString().length + 1,
|
66 | result,
|
67 | ruleName,
|
68 | });
|
69 | }
|
70 | },
|
71 | });
|
72 | });
|
73 | };
|
74 | }
|
75 |
|
76 | rule.ruleName = ruleName;
|
77 | rule.messages = messages;
|
78 | module.exports = rule;
|