Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flow compatibility #20

Merged
merged 5 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ npm install eslint-config-mixmax --save-dev

Install this config's peer dependencies if you haven't already:
```sh
yarn add -D "eslint@>=3"
yarn add -D "eslint@>=4.14.0"
```
or
```sh
npm install --save-dev "eslint@>=3"
npm install --save-dev "eslint@>=4.14.0"
```

If you'll be using the `browser` configs, make sure to install the optional `eslint-plugin-react` and `babel-eslint` dependencies.
```sh
yarn add -D "eslint-plugin-react@^7.1.0" "babel-eslint@^7.2.3"
yarn add -D "eslint-plugin-react@^7.1.0" "babel-eslint@^8.2.1"
```
or
```sh
npm install --save-dev "eslint-plugin-react@^7.1.0" "babel-eslint@^7.2.3"
npm install --save-dev "eslint-plugin-react@^7.1.0" "babel-eslint@^8.2.1"
```

If you'll be using the `flow` configs, make sure to install the optional `eslint-plugin-flowtype` and `babel-eslint` dependencies.
```sh
yarn add -D "eslint-plugin-flowtype@^2.41.0" "babel-eslint@^8.2.1"
```
or
```sh
npm install --save-dev "eslint-plugin-flowtype@^2.41.0" "babel-eslint@^8.2.1"
```

## Usage
Expand All @@ -46,24 +55,36 @@ in the appropriate directories: extend…

* "mixmax/node", in directories containing Node.js code.
* "mixmax/node/spec", in directories containing Node specs (assumed to be using Jasmine).
* "mixmax/node/ava", in directories containing ava tests.
* "mixmax/node/next", in projects using node 8 syntax (should also extend mixmax/node).
* "mixmax/flow", in projects using flow for type checking (should also extend mixmax/node or mixmax/browser).
* "mixmax/browser", in directories containing browser code. `eslint-plugin-react` is enabled in this configuration to allow for React-specific linting. Additionally, `Backbone` and `$` are globalized so that their `import` statements are not required by the linter (though they should be - see TODOs in this configuration file).
* "mixmax/browser/spec", in directories containing browser specs (assumed to be using Jasmine).

These configurations assume that you're using Node 7.6.0 or higher.

Configurations for browser code and specs are forthcoming.
Configurations for jest is forthcoming.

If you want you can extend the base configuration directly (`"extends": "mixmax"`) but you shouldn't
need to since the Node and browser configurations already extend that.

## Roadmap

At v0.1.0, this config is starting off very minimal—pretty much just ESLint's recommended
rules (the checkmarked rules [here](http://eslint.org/docs/rules)).
At v1.0.0, we've implemented configs for the common project types, and update rules as new conventions arise (still mostly ESLint's recommended set though (the checkmarked rules [here](http://eslint.org/docs/rules)). New rules should have justification for their use and a small analysis of the impact on existing code.

We may wish to adopt a more comprehensive / style-oriented spec like [Airbnb’s](https://github.com/airbnb/javascript),
since team members write JS, especially ES6, in slightly different ways; but in the interest of not
immediately breaking our projects I’ve deferred this till later.

This repository should probably document whatever styles we end up adopting, i.e. we should migrate
https://github.com/mixmaxhq/code-styles#js to here.

## Changelog

* 1.0.0 Add flow support and *BREAKING* upgrade minimum eslint version to `4.14.0`.
* 0.7.0 Enforce `arrow-parens` with error.
* 0.6.0 Add `ava` config
* 0.5.0 Globalize `analytics` in `browser` configs.
* 0.4.2 Make `babel-eslint` an optional dependency.
* 0.4.1 Make `eslint-plugin-react` an optional dependency.
* 0.4.0 Add `browser` and `browser/spec` configs.
4 changes: 2 additions & 2 deletions browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = {
globals: {
// TODO: We should not globalize this - we should explicitly import our CDN-sourced dependencies.
Backbone: true,

/**
* We need to globalize `analytics` because of the way Segment's library loads. It redefines
* `window.analytics` after loading, which, when `analytics` is not globalized, causes issues
* because the `analytics` rollup catches may not be the `window.analytics` we want.
*/
analytics: true
analytics: true
},
rules: {
'react/jsx-wrap-multilines': 2
Expand Down
33 changes: 33 additions & 0 deletions flow/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
parser: 'babel-eslint',
plugins: [
// Allows correct parsing of flow annotated files.
'flowtype'
],
rules: {
// Makes flow `type` definitions defines
'flowtype/define-flow-type': 1,
// Do not allow spaces before type declarations, i.e. let a: number, not let a : number
'flowtype/space-before-type-colon': [
1,
'never'
],
// Marks flow type declarations as used to prevent no-unused-vars for types
'flowtype/use-flow-type': 1,
// Enforces camelcase for type definitions
'flowtype/type-id-match': [
2,
'^([A-Z]+[a-z0-9A-Z]*)$'
]
},
settings: {
// Only use the flow linter for files with `@flow`
flowtype: {
onlyFilesWithFlowAnnotation: true
}
},
parserOptions: {
// Required to support import/export syntax when using types
sourceType: 'module'
}
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
}
}
}],
// Console logs should be mostly nonexistent, and places like app.js should just have a
// Console logs should be mostly nonexistent, and places like app.js should just have a
// /* eslint-disable no-console */
// comment at the top.
'no-console': ['error'],
Expand Down
7 changes: 7 additions & 0 deletions node/next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet

parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true
}
}
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
},
"homepage": "https://github.com/mixmaxhq/eslint-config-mixmax#readme",
"optionalDependencies": {
"babel-eslint": "^7.2.3",
"babel-eslint": "^8.2.1",
"eslint-plugin-flowtype": "^2.41.0",
"eslint-plugin-react": "^7.1.0"
},
"peerDependencies": {
"eslint": ">= 3"
"eslint": ">=4.14.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please update the README with updated dependency installation instructions? (describing the optional flowtype dependency and updating the version of eslint that needs to be installed)

separately, it looks like the README is outdated in other ways - mentioning forthcoming configs that have already been added, not including the jest config, requiring node >=7.6.0, and describing the project as being at v0.1 - i'm happy to clean these up after you merge this or feel free if you want to knock them out while you're in here.

},
"devDependencies": {
"eslint": ">=3",
"eslint": ">=4.14.0",
"eslint-config-mixmax": "^0.7.0",
"pre-commit": "^1.2.2"
},
Expand Down
Loading