Skip to content

Commit

Permalink
fix small options
Browse files Browse the repository at this point in the history
  • Loading branch information
David B committed Dec 3, 2018
1 parent c9c3f2d commit dff414a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 43 deletions.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/DavidBabel/check-flow-annotation.svg?branch=master)](https://travis-ci.org/DavidBabel/check-flow-annotation)
[![codecov](https://codecov.io/gh/DavidBabel/check-flow-annotation/branch/master/graph/badge.svg)](https://codecov.io/gh/DavidBabel/check-flow-annotation)

<!-- [![codecov](https://codecov.io/gh/DavidBabel/check-flow-annotation/branch/master/graph/badge.svg)](https://codecov.io/gh/DavidBabel/check-flow-annotation) -->

[![npm](http://img.shields.io/npm/v/check-flow-annotation.svg)](https://www.npmjs.com/package/check-flow-annotation)
[![License](https://img.shields.io/npm/l/check-flow-annotation.svg)](LICENSE)
Expand All @@ -13,23 +13,39 @@ This is a very simple package to check your flow annotation coverage over your p
This one is made to be included in your CI to prevent to forget some type annotations. It's very fast, and allow some customisations.

```bash
# install
# install with yarn
yarn add check-flow-annotation -D
# install with npm
npm install check-flow-annotation --save-dev

# usages in your CI config
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'
```

```bash
# help
check-flow-annotation -h

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
Displays help information about this script
Expand All @@ -43,13 +59,11 @@ Usage: check-flow-annotation.js [options] path1 path2 path3 etc
Force to check for "@flow strict"

--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)']

--check, -c
Set a custom check
'@flow weak' or '@no flow'

```

68 changes: 35 additions & 33 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function exec(inputArgs = argv) {
const args = inputArgs
.info(
`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"`
)
.version('v1.0')
.option([
Expand All @@ -25,9 +28,10 @@ function exec(inputArgs = argv) {
name: 'exclude',
short: 'x',
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)']`
},
{
name: 'check',
Expand Down Expand Up @@ -69,39 +73,37 @@ function exec(inputArgs = argv) {
});
};

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();
}
);
});
});
}

Expand Down

0 comments on commit dff414a

Please sign in to comment.