/
no-eol-whitespace.js
62 lines (56 loc) · 1.43 KB
/
no-eol-whitespace.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict"
const coreRule = require("../utils/stylelint-v15/rules/no-eol-whitespace")
const { transformResult } = require("../utils/proxy")
const ruleName = "stylus/no-eol-whitespace"
const originalRuleName = "no-eol-whitespace"
function rule(expectation, options, context) {
const verify = coreRule(expectation, options, context)
return (root, result) => {
if (root.source.lang !== "stylus") {
verify(
root,
transformResult(result, {
originalRuleName,
ruleName,
}),
)
return
}
if (context.fix) {
fixForStylus(root)
}
verify(
root,
transformResult(result, {
originalRuleName,
ruleName,
}),
)
}
}
module.exports = {
ruleName,
rule,
meta: {
docs: {
description: "disallow end-of-line whitespace.",
category: "standard",
},
fixable: true,
},
}
function fixForStylus(root) {
root.walkAtRules(fixForPythonic)
root.walkRules(fixForPythonic)
function fixForPythonic(node) {
if (!node.pythonic) {
return
}
if (node.raws.between) {
node.raws.between = node.raws.between.replace(
/(^|[\n\r])[^\S\n\r]+$/u,
"",
)
}
}
}