check-flow-annotation
Advanced tools
Comparing version
{ | ||
"name": "check-flow-annotation", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A basic flow type annotation checker", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
[](https://travis-ci.org/DavidBabel/check-flow-annotation) | ||
[](https://codecov.io/gh/DavidBabel/check-flow-annotation) | ||
<!-- [](https://codecov.io/gh/DavidBabel/check-flow-annotation) --> | ||
@@ -16,4 +16,5 @@ [](https://www.npmjs.com/package/check-flow-annotation) | ||
```bash | ||
# install | ||
# install with yarn | ||
yarn add check-flow-annotation -D | ||
# install with npm | ||
npm install check-flow-annotation --save-dev | ||
@@ -23,5 +24,17 @@ | ||
check-flow-annotation ./my/path ./my/other/path | ||
# with options | ||
check-flow-annotation ./my/path --strict | ||
check-flow-annotation ./my/path --exclude ['build*', '.src/static/*'] | ||
check-flow-annotation ./my/path --check '@flow weak' | ||
check-flow-annotation --strict ./my/path # same | ||
# exclude some paths | ||
check-flow-annotation ./my/path --exclude='build*','.src/static/*' | ||
check-flow-annotation ./my/path -x 'build*','.src/static/*' #same, small version | ||
check-flow-annotation ./my/path -x 'build*' -x '.src/static/*' #same | ||
# exclude jsx files | ||
check-flow-annotation ./my/path --exclude='*.jsx' | ||
# check another anotation on first line | ||
check-flow-annotation ./my/path --check='@flow weak' | ||
``` | ||
@@ -34,4 +47,7 @@ | ||
Usage: check-flow-annotation.js [options] path1 path2 path3 etc | ||
by default it checks every ".js" and ".jsx" in your project, but you can filter it with exclude option | ||
By default it checks every ".js" and ".jsx" in your project, but you can filter it with exclude option | ||
Note that options are written "--option=value" but short version are written "-o value" | ||
--help, -h | ||
@@ -49,5 +65,5 @@ Displays help information about this script | ||
--exclude, -x | ||
Allow to exclude certain paths or extensions | ||
example: ['build*', '.src/static/*', '*.jsx'] | ||
will be merged with default: ['node_modules*', '.git*', 'flow-typed*', '.*', '!*.+(js|jsx)'] | ||
Allow to exclude certain paths or extensions, it‘s a comma separated value | ||
example: 'build*','.src/static/*' | ||
will be merged with default array: ['node_modules*', '.git*', 'flow-typed*', '.*', '!*.+(js|jsx|mjs)'] | ||
@@ -57,4 +73,2 @@ --check, -c | ||
'@flow weak' or '@no flow' | ||
``` | ||
@@ -14,3 +14,6 @@ #!/usr/bin/env node | ||
`Usage: check-flow-annotation.js [options] path1 path2 path3 etc | ||
by default it checks every ".js" and ".jsx" in your project, but you can filter it with exclude option` | ||
By default it checks every ".js" and ".jsx" in your project, but you can filter it with exclude option | ||
Note that options are written "--option=value" but short versions are written "-o value"` | ||
) | ||
@@ -29,5 +32,6 @@ .version('v1.0') | ||
type: 'list,csv', | ||
description: 'Allow to exclude certain paths or extensions', | ||
example: `example: ['build*', '.src/static/*', '*.jsx'] | ||
will be merged with default: ['node_modules*', '.git*', 'flow-typed*', '.*', '!*.+(js|jsx)']` | ||
description: | ||
'Allow to exclude certain paths or extensions, it‘s a comma separated value', | ||
example: `example: 'build*','.src/static/*' | ||
will be merged with default array: ['node_modules*', '.git*', 'flow-typed*', '.*', '!*.+(js|jsx|mjs)']` | ||
}, | ||
@@ -74,35 +78,33 @@ { | ||
const excludeDirs = [ | ||
'node_modules*', | ||
'.git*', | ||
'flow-typed*', | ||
'.*', | ||
'!*.+(js|jsx|mjs)', | ||
...flatten(exclude) | ||
]; | ||
targets.forEach(target => { | ||
readDir( | ||
target, | ||
[ | ||
'node_modules*', | ||
'.git*', | ||
'flow-typed*', | ||
'.*', | ||
'!*.+(js|jsx)', | ||
...flatten(exclude) | ||
], | ||
(err, files) => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
readDir(target, excludeDirs, (err, files) => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
promises.push( | ||
...files.map(async file => { | ||
const line = await firstline(file); | ||
if (!checkRegexp.test(line)) { | ||
return `${`missing ${annotation} annotation:`.red} ${file}`; | ||
} | ||
return null; | ||
}) | ||
); | ||
promises.push( | ||
...files.map(async file => { | ||
const line = await firstline(file); | ||
if (!checkRegexp.test(line)) { | ||
return `${`missing ${annotation} annotation:`.red} ${file}`; | ||
} | ||
return null; | ||
}) | ||
); | ||
pathsLeft--; | ||
if (pathsLeft === 0) { | ||
printResult(); | ||
} | ||
pathsLeft--; | ||
if (pathsLeft === 0) { | ||
printResult(); | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -109,0 +111,0 @@ } |
7554
8.44%70
25%101
-0.98%