forked from todogroup/repolinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-not-exists.js
45 lines (41 loc) · 1.31 KB
/
file-not-exists.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
// Copyright 2017 TODO Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
const Result = require('../lib/result')
// eslint-disable-next-line no-unused-vars
const FileSystem = require('../lib/file_system')
/**
* Check if a file is not present in the repository. Fails on the first file
* matching the glob pattern, succeeds if no file matching any of the patterns
* is found.
*
* @param {FileSystem} fs A filesystem object configured with filter paths and target directories
* @param {object} options The rule configuration
* @returns {Promise<Result>} The lint rule result
* @ignore
*/
async function fileNotExistence(fs, options) {
const fileList = options.globsAll
const file = options.dirs
? await fs.findAll(fileList, options.nocase)
: await fs.findAllFiles(fileList, options.nocase)
return file.length !== 0
? new Result(
'Found files',
file.map(f => {
return { passed: false, path: f }
}),
false
)
: new Result(
`${
options['pass-message'] !== undefined
? options['pass-message'] + '. '
: ''
}Did not find a file matching the specified patterns`,
fileList.map(f => {
return { pattern: f, passed: true }
}),
true
)
}
module.exports = fileNotExistence