Skip to content

Commit

Permalink
[tests] add test for flow prettier formated
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Jul 18, 2017
1 parent 9843c0f commit 4475090
Show file tree
Hide file tree
Showing 23 changed files with 529 additions and 10 deletions.
2 changes: 1 addition & 1 deletion documentation/with-flow.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### with flow
## with flow
Flowtype rules will be accepted if the flow annotation was defined in first line of each file.
```
module.exports = {
Expand Down
18 changes: 14 additions & 4 deletions documentation/with-prettier.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
### with prettier

If you using prettier you should disable all eslint styling rules
## with prettier

### ES6 + Prettier
```
module.exports = {
"extends": [
Expand All @@ -11,13 +10,24 @@ module.exports = {
};
```

### ES6 + React + Prettier
```
module.exports = {
"extends": [
"@namics/eslint-config/configurations/es6-react.js",
"@namics/eslint-config/configurations/es6-react-disable-styles.js"
]
};
```

### ES6 + React + Flow + Prettier
```
module.exports = {
"extends": [
"@namics/eslint-config/configurations/es6-react.js",
"@namics/eslint-config/configurations/es6-react-disable-styles.js",
"@namics/eslint-config/configurations/flow.js",
"@namics/eslint-config/configurations/flow.js-disable-styles"
"@namics/eslint-config/configurations/flow-disable-styles.js"
]
};
```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"lint": "npm run lint:js",
"lint:js": "node_modules/.bin/eslint .",
"test": "npm run lint",
"prettier": "npm run prettier:es5 && npm run prettier:es5node && npm run prettier:es6 && npm run prettier:es6react",
"prettier": "npm run prettier:es5 && npm run prettier:es5node && npm run prettier:es6 && npm run prettier:es6react && npm run prettier:flow",
"prettier:es5": "node_modules/.bin/prettier --write \"test/es5-disable-styles/**/*.js\"",
"prettier:es5node": "node_modules/.bin/prettier --write \"test/es5-node-disable-styles/**/*.js\"",
"prettier:es6": "node_modules/.bin/prettier --write \"test/es6-disable-styles/**/*.js\"",
"prettier:es6react": "node_modules/.bin/prettier --write \"test/es6-react-disable-styles/**/*.js\""
"prettier:es6react": "node_modules/.bin/prettier --write \"test/es6-react-disable-styles/**/*.js\"",
"prettier:flow": "node_modules/.bin/prettier --write \"test/flow-disable-styles/**/*.js\""
},
"keywords": [
"code checker",
Expand Down
6 changes: 3 additions & 3 deletions test/es6-react-disable-styles/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
extends: [
"../../configurations/es6-react.js",
"../../configurations/es6-react-disable-styles.js",
],
"../../configurations/es6-react.js",
"../../configurations/es6-react-disable-styles.js"
]
};
8 changes: 8 additions & 0 deletions test/flow-disable-styles/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: [
"../../configurations/es6-browser.js",
"../../configurations/es6-browser-disable-styles.js",
"../../configurations/flow.js",
"../../configurations/flow-disable-styles.js",
],
};
29 changes: 29 additions & 0 deletions test/flow-disable-styles/rules/flow/boolean-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @flow
// DESCRIPTION = enforces a particular style for boolean type annotations. This rule takes one argument.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// GOOD
type AeType = boolean;

// BAD
/*
type BeType = bool;
type CeType = Boolean;
*/
// END!>
28 changes: 28 additions & 0 deletions test/flow-disable-styles/rules/flow/define-flow-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @flow
// DESCRIPTION = 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.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
const a: AeType = '';
*/
// GOOD
type BeType = string;
const b: BeType = "";
// END!>
27 changes: 27 additions & 0 deletions test/flow-disable-styles/rules/flow/delimiter-dangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
// DESCRIPTION = enforces consistent use of trailing commas in Object and Tuple annotations.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
type AeType = {
foo: string
};
*/
// GOOD
type BeType = {
foo: string
};
// END!>
27 changes: 27 additions & 0 deletions test/flow-disable-styles/rules/flow/generic-spacing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
// DESCRIPTION = enforces consistent spacing within generic type annotation parameters.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
type AeType = Promise< string>;
*/
// GOOD
type BeType = Promise<string>;
// END!>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @flow
// DESCRIPTION = disallows use of primitive constructors as types, such as `Boolean`, `Number` and `String`. [See more](https://flowtype.org/docs/builtins.html).
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
type NumberType = Number;
type StringType = String;
type BooleanType = Boolean;
*/

// GOOD
type NumberType = number;
type StringType = string;
type BooleanType = boolean;
// END!>
30 changes: 30 additions & 0 deletions test/flow-disable-styles/rules/flow/no-weak-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow
// DESCRIPTION = 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.
// STATUS = 0

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
function foo(thing: string): any {
return true;
}

// GOOD
function foo(thing: string): boolean {
return true;
}
// END!>
35 changes: 35 additions & 0 deletions test/flow-disable-styles/rules/flow/object-type-delimiter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @flow
// DESCRIPTION = enforces consistent separators between properties in Flow object types.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
type FooType = { a: string; b: string };
type Foo2Type = {
a: string,
b: string
};
*/
// GOOD
type FooType = { a: string, b: string };
type Foo2Type = {
a: string,
b: string
};
// END!>
25 changes: 25 additions & 0 deletions test/flow-disable-styles/rules/flow/require-jsdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @flow
// DESCRIPTION = Overwrite require-jsdoc rule
// STATUS = 0

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// jsdoc is not required if you are using flow
function foo(thing: string): any {
return true;
}
// END!>
27 changes: 27 additions & 0 deletions test/flow-disable-styles/rules/flow/require-parameter-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
// DESCRIPTION = requires that all function parameters have type annotations.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
function x(foo) {}
*/
// GOOD
function x(foo: string) {}
// END!>
29 changes: 29 additions & 0 deletions test/flow-disable-styles/rules/flow/require-return-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @flow
// DESCRIPTION = requires that functions have return type annotation.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// BAD
/*
const a = (foo: string) => { return 'foo'; };
*/
// GOOD
const b = (foo: string): string => {
return "foo";
};
// END!>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @flow
// DESCRIPTION = this rule validates Flow file annotations.
// STATUS = 2

/* eslint max-len: 0*/
/* eslint require-jsdoc: 0*/
/* eslint no-use-before-define: 0*/
/* eslint no-undef: 0*/
/* eslint no-unused-vars: 0*/
/* eslint no-unreachable: 0*/
/* eslint no-empty: 0*/
/* eslint no-empty-function: 0*/
/* eslint no-shadow: 0*/
/* eslint no-redeclare: 0*/
/* eslint react/react-in-jsx-scope: 0*/
/* eslint react/prefer-stateless-function: 0*/
/* eslint react/prefer-es6-class: 0*/
/* eslint react/prop-types: 0*/
/* eslint object-shorthand: 0*/
// <!START
// @flow
// or
/* @flow */
// END!>
Loading

0 comments on commit 4475090

Please sign in to comment.