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