Skip to content

Commit e64173a

Browse files
committed
fix: better scanning, add json to prettier
1 parent b71fbc0 commit e64173a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

bin/lint.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const argv = yargs.usage('Usage: $0 [options]').option('fix', {
1313
function scanFor(file, maxDepth = 3) {
1414
let pathToFile = path.join(process.cwd(), file)
1515
while (pathToFile.length > file.length + 1 && !fs.existsSync(pathToFile) && maxDepth >= 0) {
16-
const parentDir = path.dirname(path.dirname(pathToFile))
16+
const parentDir = path.dirname(pathToFile.substr(0, pathToFile.length - file.length))
1717
pathToFile = path.join(parentDir, file)
1818
maxDepth--
1919
}
@@ -22,9 +22,21 @@ function scanFor(file, maxDepth = 3) {
2222
}
2323

2424
const TSCONFIG_PATH = scanFor('tsconfig.json')
25+
const TSLINT_PATH = scanFor('node_modules/.bin/tslint')
26+
const ESLINT_PATH = scanFor('node_modules/.bin/eslint')
27+
const PRETTIER_PATH = scanFor('node_modules/.bin/prettier')
28+
const TSLINTRC_PATH = scanFor('tslint.json')
2529
const ESLINTRC_PATH = scanFor('.eslintrc')
2630

27-
if (!TSCONFIG_PATH && !ESLINTRC_PATH) {
31+
if (!TSLINT_PATH && !ESLINT_PATH) {
32+
throw new Error('Must have either eslint or tslint installed')
33+
}
34+
35+
if (!PRETTIER_PATH) {
36+
throw new Error('Must have prettier installed')
37+
}
38+
39+
if (!TSLINTRC_PATH && !ESLINTRC_PATH) {
2840
throw new Error('Must have either eslint or tslint config')
2941
}
3042

@@ -42,9 +54,10 @@ const directories = `{packages/*/,./}{src/**/,lib/**/,bin/**/,test/**/,}`
4254

4355
const lintFixArg = argv.fix ? '--fix' : ''
4456
const lintCommand = TSCONFIG_PATH
45-
? `tslint --project . -c ${TSCONFIG_PATH}`
46-
: `eslint -c ${ESLINTRC_PATH} '${directories}*.js'`
57+
? `${TSLINT_PATH} --project . -c ${TSLINTRC_PATH}`
58+
: `${ESLINT_PATH} -c ${ESLINTRC_PATH} '${directories}*.js'`
4759
const lintPassed = exec(`${lintCommand} ${lintFixArg}`)
4860
const prettierFixArg = argv.fix ? '--write' : '--list-different'
49-
const prettierPassed = exec(`prettier ${prettierFixArg} '${directories}*.{ts,css,scss,md}'`)
61+
const prettierFiles = `${directories}*.{ts,css,scss,md,json}`
62+
const prettierPassed = exec(`${PRETTIER_PATH} ${prettierFixArg} '${prettierFiles}'`)
5063
process.exit(lintPassed && prettierPassed ? 0 : 1)

0 commit comments

Comments
 (0)