-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule.js
More file actions
47 lines (41 loc) · 1.39 KB
/
rule.js
File metadata and controls
47 lines (41 loc) · 1.39 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
const support = require('./support');
const fs = require('fs');
const fileList = require('./glob')
.then((list) => {
removeAnnotationFunc(list);
});
const errMsg = "can't find the js file inside the project.";
let errorList = [];
function removeAnnotationFunc(pathList) {
pathList.forEach(file => {
fileRead(file).then((tmp) => {
//contentToArray
const content = support.toArray(support.removeComment(tmp));
//check Korean
let errIdx = support.booleanArr(content.length);
let errFlag = false;
content.forEach((item, idx) => {
if(support.checkLiteral(item)) {
if(idx-1>=0) errIdx[idx-1] = true;
if(idx+1<content.length) errIdx[idx+1] = true;
errIdx[idx] = true;
errFlag = true;
}
});
//createErrorList
errFlag ? errorList.push(...support.createErrorList(file, content, errIdx)) : '';
})
});
}
function fileRead(file) {
return new Promise( (resolve, reject)=> {
fs.readFile(file, 'utf-8', (err, tmp) => {
tmp ? resolve(tmp) : reject(new Error(errMsg));
});
});
}
module.exports = new Promise( (resolve, reject) => {
setTimeout(() => {
typeof errorList !== 'undefined' ? resolve(errorList) : reject;
},100);
});