Skip to content

Commit

Permalink
feat(basic): exclude all invalid files
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed May 12, 2023
1 parent 2db56ec commit 2623dab
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions packages/eslint-config-basic/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
const fs = require('node:fs')

// only files with extension below will be checked
const VALID_EXTENSION = [
'js', 'cjs', 'mjs', 'jsx',
'ts', 'cts', 'mts', 'tsx',
'json', 'json5',
'yaml', 'yml',
'html', 'vue',
'md',
]

function isInvalidFile(path) {
return !VALID_EXTENSION.some(ext => path.toLowerCase().endsWith(`.${ext}`))
}

function isFile(path) {
let stats
try {
stats = fs.statSync(path)
}
catch (e) {
return false
}
return stats.isFile()
}

// ignore for lint-staged
const ignorePatterns = process.argv
.slice(2)
.filter(i => !i.startsWith('-'))
.filter(isFile)
.filter(isInvalidFile)
.map(p => `*.${p.split('.').at(-1)}`)
.filter((i, index, arr) => arr.indexOf(i) === index)

// console.log(ignorePatterns)

module.exports = {
env: {
es6: true,
Expand Down Expand Up @@ -28,23 +66,14 @@ module.exports = {
'pnpm-lock.yaml',
'yarn.lock',
'__snapshots__',
// ignore for in lint-staged
'*.css',
'*.png',
'*.ico',
'*.toml',
'*.patch',
'*.txt',
'*.crt',
'*.key',
'Dockerfile',
// force include
'!.github',
'!.vitepress',
'!.vscode',
// force exclude
'.vitepress/cache',
],
].concat(ignorePatterns),
plugins: [
'html',
'unicorn',
Expand Down

0 comments on commit 2623dab

Please sign in to comment.