Skip to content

Commit

Permalink
[add] flow config and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Apr 4, 2017
1 parent 74c38c8 commit 5ef665f
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 21 deletions.
9 changes: 9 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ignore]

[include]

[libs]

[options]
unsafe.enable_getters_and_setters=true
esproposal.decorators=ignore
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
$ npm install --save-dev eslint eslint-plugin-import @namics/eslint-config
```


## Usage
- `@namics/eslint-config/configurations/es6-browser` - ES6 + browser
- `@namics/eslint-config/configurations/es6-react` - ES6 + react
Expand All @@ -28,12 +27,13 @@ module.exports = {
```

### with flow
Flowtype rules will be accepted if the flow annotation was defined in first line of each file.
```
module.exports = {
"extends": [
"@namics/eslint-config/configurations/flow.js"
"@namics/eslint-config/configurations/es6-react.js"
]
],
}
```

Expand Down Expand Up @@ -91,4 +91,4 @@ then run `npm run lint`


## Changelog
Please see the [Releases](https://github.com/namics/eslint-config-namics/releases)
Please see the [Releases](https://github.com/namics/eslint-config-namics/releases)
12 changes: 6 additions & 6 deletions configurations/es5.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {

extends: [
'../rules/es6-disable',
'../rules/node-disable',
'../rules/best-practices',
'../rules/errors',
'../rules/style',
'../rules/variables',
'../rules/es6-disable.js',
'../rules/node-disable.js',
'../rules/best-practices.js',
'../rules/errors.js',
'../rules/style.js',
'../rules/variables.js',
].map(require.resolve),
env: {},
parserOptions: {
Expand Down
4 changes: 2 additions & 2 deletions configurations/es6-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = {
],
'extends': [
'./es6.js',
'../rules/react',
'../rules/react-a11y',
'../rules/react.js',
'../rules/react-a11y.js',
].map(require.resolve),
'env': {
'browser': true,
Expand Down
14 changes: 7 additions & 7 deletions configurations/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ module.exports = {
},
},
extends: [
'../rules/node-disable',
'../rules/best-practices',
'../rules/errors',
'../rules/style',
'../rules/variables',
'../rules/imports',
'../rules/es6',
'../rules/node-disable.js',
'../rules/best-practices.js',
'../rules/errors.js',
'../rules/style.js',
'../rules/variables.js',
'../rules/imports.js',
'../rules/es6.js',
].map(require.resolve),

parserOptions: {
Expand Down
16 changes: 16 additions & 0 deletions configurations/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

module.exports = {

'parser': 'babel-eslint',
'plugins': [
'flowtype',
],
'extends': [
'../rules/flow.js',
],
'settings': {
'flowtype': {
'onlyFilesWithFlowAnnotation': true,
},
},
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"main": "configurations/es6-browser.js",
"scripts": {
"lint": "npm run lint:js",
"lint:js": "node_modules/.bin/eslint test/**/*.jsx test/**/*.js",
"lint:js": "node_modules/.bin/eslint .",
"test": "npm run lint"
},
"keywords": [
Expand All @@ -39,8 +39,11 @@
"eslint-plugin-import": "^2.0.0"
},
"dependencies": {
"babel-eslint": "^7.2.1",
"eslint-find-rules": "^1.14.3",
"eslint-plugin-flowtype": "^2.30.4",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.0"
"eslint-plugin-react": "^6.10.0",
"flow-bin": "^0.40.0"
}
}
18 changes: 17 additions & 1 deletion processing/write-rule-test-files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/* eslint "no-console": 0 */

/*
USAGE:
node processing/write-rule-test-files.js rules/flow.js test/flow/rules/
*/

var utils = require('./utils');
var argv = process.argv;
var filePath;
Expand All @@ -20,8 +27,10 @@ function writeTestFiles() {
destPath = argv[3];
data = utils.readFile(filePath);


data.split('\n\n').map(function (rule) {


var ruleSpl = rule.split('\n');
var desc;
var destFileName;
Expand All @@ -40,10 +49,17 @@ function writeTestFiles() {
.replace(/\[([^, {]*).*/g, '$1')
.replace(/'/g, '');

if (nameStatus.search(/^http/) >= 0) {
nameStatus = ruleSpl[2]
.replace('//', '')
.trim()
.replace(/\[([^, {]*).*/g, '$1')
.replace(/'/g, '');
}

nameStatusSpl = nameStatus.split(':');

destFileName = destPath + nameStatusSpl[0].replace(/^.*\//, '') + '.js';

if (utils.existFile(destFileName)) {
return true;
}
Expand Down
88 changes: 88 additions & 0 deletions rules/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-disable */
/* global module */
/* not yet approved by skill group core team */
module.exports = {
rules: {

// Overwrite require-jsdoc rule
'require-jsdoc': 0,

// enforces a particular style for boolean type annotations. This rule takes one argument.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-boolean-style
'flowtype/boolean-style': [2, 'boolean'],

// marks Flow type identifiers as defined. Used to suppress [`no-undef`](https://github.com/gajus/eslint-plugin-flowtypedocs/rules/no-undef) reporting of type identifiers.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-define-flow-type
'flowtype/define-flow-type': 2,

// enforces consistent use of trailing commas in Object and Tuple annotations.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-delimiter-dangle
'flowtype/delimiter-dangle': [2, 'always-multiline'],
// [20.09.2016] always-multiline -> https://github.com/namics/eslint-config-namics/issues/1

// enforces consistent spacing within generic type annotation parameters.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-generic-spacing
'flowtype/generic-spacing': [2, 'never'],

// disallows use of primitive constructors as types, such as `Boolean`, `Number` and `String`. [See more](https://flowtype.org/docs/builtins.html).
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-no-primitive-constructor-types
'flowtype/no-primitive-constructor-types': 2,

// Warns against weak type annotations *any*, *Object* and *Function*. These types can cause flow to silently skip over portions of your code, which would have otherwise caused type errors.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-no-weak-types
'flowtype/no-weak-types': 0,
// [10.03.2013] disabled because of third party libraries

// enforces consistent separators between properties in Flow object types.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter
'flowtype/object-type-delimiter': [2, 'comma'],

// requires that all function parameters have type annotations.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-require-parameter-type
'flowtype/require-parameter-type': 2,

// requires that functions have return type annotation.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-require-return-type
'flowtype/require-return-type': [2, 'always',
{
'annotateUndefined': 'never',
},
],

// this rule validates Flow file annotations.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-require-valid-file-annotation
'flowtype/require-valid-file-annotation': 2,

// enforces consistent use of semicolons after type aliases.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-semi
'flowtype/semi': [2, 'always'],

// enforces consistent spacing after the type annotation colon.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-space-after-type-colon
'flowtype/space-after-type-colon': [2, 'always'],

// Enforces consistent spacing before the opening < of generic type annotation parameters.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-space-before-generic-bracket
'flowtype/space-before-generic-bracket': [2, 'never'],

// Enforces consistent spacing before the type annotation colon.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-space-before-type-colon
'flowtype/space-before-type-colon': [2, 'never'],

// Enforces a consistent naming pattern for type aliases.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-type-id-match
'flowtype/type-id-match': [2, '^([A-Z][a-z0-9]+)+Type$'],

// Enforces consistent spacing around union and intersection type separators (| and &).
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-union-intersection-spacing
'flowtype/union-intersection-spacing': [2, 'always'],

// Marks Flow type alias declarations as used. Used to suppress no-unused-vars errors that are triggered by type aliases.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-use-flow-type
'flowtype/use-flow-type': 2,

// Checks for simple Flow syntax errors.
// https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-valid-syntax
'flowtype/valid-syntax': 2,
},
};

0 comments on commit 5ef665f

Please sign in to comment.