-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy patheof-newline.js
More file actions
65 lines (55 loc) · 1.25 KB
/
eof-newline.js
File metadata and controls
65 lines (55 loc) · 1.25 KB
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
'use strict';
let gonzales = require('gonzales-pe');
let os = require('os');
let option = {
/**
* Option's name as it's used in config.
* @type {String}
*/
get name() {
return 'eof-newline';
},
/**
* List of syntaxes that are supported by this option.
* @type {Array}
*/
get syntax() {
return ['css', 'less', 'sass', 'scss'];
},
/**
* Types of values this option accepts in config.
* @type {Object}
*/
get accepts() {
return {
boolean: [true, false]
};
},
/**
* Processes ast and fixes found code style errors.
* @param {Node} ast
*/
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(/\r?\n$/, '');
if (this.value) lastChild.content += os.EOL;
},
/**
* Detects the value of this option in ast.
* @param {Node} ast
* @return {Array} List of detected values
*/
detect(ast) {
var lastChild = ast.last();
if (lastChild.is('space') && lastChild.content.indexOf('\n') !== -1) {
return [true];
} else {
return [false];
}
}
};
module.exports = option;