|
| 1 | +// Copyright 2022 TODO Group. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// eslint-disable-next-line no-unused-vars |
| 5 | +const Result = require('../lib/result') |
| 6 | +// eslint-disable-next-line no-unused-vars |
| 7 | +const FileSystem = require('../lib/file_system') |
| 8 | +const fileNotContents = require('./file-not-contents') |
| 9 | + |
| 10 | +/** |
| 11 | + * Check if a list of files contains a list of regular expressions. |
| 12 | + * |
| 13 | + * @param {FileSystem} fs A filesystem object configured with filter paths and target directories |
| 14 | + * @param {object} options The rule configuration |
| 15 | + * @returns {Promise<Result>} The lint rule result |
| 16 | + */ |
| 17 | +async function filesNotContents(fs, options) { |
| 18 | + const results = await Promise.all( |
| 19 | + options.contents.map(content => { |
| 20 | + const singleOption = { ...options } |
| 21 | + delete singleOption.contents |
| 22 | + singleOption.content = content |
| 23 | + return fileNotContents(fs, singleOption) |
| 24 | + }) |
| 25 | + ) |
| 26 | + |
| 27 | + const filteredResults = results.filter(r => r !== null) |
| 28 | + console.log(filteredResults) |
| 29 | + const passed = !filteredResults.find(r => !r.passed) |
| 30 | + const aggregatedTargets = filteredResults |
| 31 | + .reduce((previous, current) => { |
| 32 | + console.log(current.targets) |
| 33 | + return previous.concat(current.targets) |
| 34 | + }, []) |
| 35 | + .filter(r => !r.passed) |
| 36 | + |
| 37 | + if (passed) { |
| 38 | + return new Result( |
| 39 | + 'Did not find content matching specified patterns', |
| 40 | + aggregatedTargets, |
| 41 | + passed |
| 42 | + ) |
| 43 | + } |
| 44 | + return new Result('', aggregatedTargets, passed) |
| 45 | +} |
| 46 | + |
| 47 | +module.exports = filesNotContents |
0 commit comments