forked from csscomb/csscomb.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eof-newline.js
80 lines (67 loc) · 1.53 KB
/
eof-newline.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
var gonzales = require('gonzales-pe');
var option = Object.defineProperties({
/**
* Processes ast and fixes found code style errors.
* @param {Node} ast
*/
process: function process(ast) {
var lastChild = ast.last();
if (!lastChild.is('space')) {
lastChild = gonzales.createNode({ type: 'space', content: '' });
ast.content.push(lastChild);
}
lastChild.content = lastChild.content.replace(/\n$/, '');
if (this.value) lastChild.content += '\n';
},
/**
* Detects the value of this option in ast.
* @param {Node} ast
* @return {Array} List of detected values
*/
detect: function detect(ast) {
var lastChild = ast.last();
if (lastChild.is('space') && lastChild.content.indexOf('\n') !== -1) {
return [true];
} else {
return [false];
}
}
}, {
name: {
/**
* Option's name as it's used in config.
* @type {String}
*/
get: function get() {
return 'eof-newline';
},
configurable: true,
enumerable: true
},
syntax: {
/**
* List of syntaxes that are supported by this option.
* @type {Array}
*/
get: function get() {
return ['css', 'less', 'sass', 'scss'];
},
configurable: true,
enumerable: true
},
accepts: {
/**
* Types of values this option accepts in config.
* @type {Object}
*/
get: function get() {
return {
boolean: [true, false]
};
},
configurable: true,
enumerable: true
}
});
module.exports = option;