1 | 'use strict'
|
2 |
|
3 | const debug = require('debug')('elint:walker:filetree')
|
4 | const path = require('path')
|
5 | const { linterSuffix } = require('../config')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function getFileTree () {
|
13 | const fileTree = {}
|
14 |
|
15 | debug('config linterSuffix: %o', linterSuffix)
|
16 |
|
17 | Object.keys(linterSuffix).forEach(linterName => {
|
18 | fileTree[linterName] = []
|
19 | })
|
20 |
|
21 | return fileTree
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function fillFileTree (fileTree, fileList) {
|
32 | let extname
|
33 |
|
34 | fileList.forEach(filePath => {
|
35 | extname = path.extname(filePath)
|
36 | const linters = Object.keys(linterSuffix)
|
37 |
|
38 | const match = linters.some(linterName => {
|
39 | if (linterSuffix[linterName].includes(extname)) {
|
40 | fileTree[linterName].push(filePath)
|
41 | return true
|
42 | }
|
43 |
|
44 | return false
|
45 | })
|
46 |
|
47 |
|
48 | if (!match) {
|
49 | linters.forEach(linterName => {
|
50 | fileTree[linterName].push(filePath)
|
51 | })
|
52 | }
|
53 | })
|
54 |
|
55 | return fileTree
|
56 | }
|
57 |
|
58 | module.exports = {
|
59 | getFileTree,
|
60 | fillFileTree
|
61 | }
|