updated the knip rules a bit

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-02-08 09:40:51 +01:00
parent 8afb5c6671
commit e97cc0b0a3
272 changed files with 451 additions and 2046 deletions
+8 -3
View File
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { spawnSync } = require('child_process');
const {
resolve: resolvePath,
@@ -21,7 +22,7 @@ const {
} = require('path');
const fs = require('fs').promises;
const IGNORED = [
const IGNORED_WHEN_LISTING = [
/^ADOPTERS\.md$/,
/^OWNERS\.md$/,
/^.*[/\\]CHANGELOG\.md$/,
@@ -31,6 +32,8 @@ const IGNORED = [
/^docs[/\\]reference[/\\]/,
];
const IGNORED_WHEN_EXPLICIT = [/^.*[/\\]knip-report\.md$/];
const rootDir = resolvePath(__dirname, '..');
// Manual listing to avoid dependency install for listing files in CI
@@ -42,7 +45,7 @@ async function listFiles(dir = '') {
.map(async file => {
const path = joinPath(dir, file);
if (IGNORED.some(pattern => pattern.test(path))) {
if (IGNORED_WHEN_LISTING.some(pattern => pattern.test(path))) {
return [];
}
if ((await fs.stat(path)).isDirectory()) {
@@ -114,7 +117,9 @@ async function main() {
const absolutePaths = process.argv
.slice(2)
.filter(path => !path.startsWith('-'));
const relativePaths = absolutePaths.map(path => relativePath(rootDir, path));
const relativePaths = absolutePaths
.map(path => relativePath(rootDir, path))
.filter(path => !IGNORED_WHEN_EXPLICIT.some(pattern => pattern.test(path)));
const success = await runVale(
relativePaths.length === 0 ? await listFiles() : relativePaths,