Skip to content

Commit

Permalink
Merge pull request #1 from shakacode/alex/npm-eslint-config
Browse files Browse the repository at this point in the history
Add npm eslint config package
  • Loading branch information
alex35mil committed Jan 6, 2016
2 parents 2dc4856 + 8182894 commit 76a8167
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
*.log
*.log*
.DS_Store
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ ShakaCode's JavaScript Style Guide (Also see our Ruby one: https://github.com/sh

# ShakaCode JavaScript Style Guide

Our **JavaScript Style Guide** is relatively simpler because we're simply using the [Airbnb JavaScript Style Guide][airbnb-javascript] with it's associated `.eslintrc` and `.jscsrc` files.
Our **JavaScript Style Guide** is relatively simpler because we're simply using the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) with it's associated `.eslintrc` and `.jscsrc` files.

Here's a few notes on top of that:

1. **Line Length**: We're sticking with the AirBnb Standard of 120, and any strings greater than 100 should be broken up to multiple lines. Airbnb moved to 120, here's [why](https://github.com/airbnb/javascript/pull/458).
2. Definitely follow the [AirBnb React Guide](https://github.com/airbnb/javascript/blob/master/react/README.md)


# Exceptions:
# Exceptions (React Guide only)

## Root Components
[AirBnb on Root components](https://github.com/airbnb/javascript/blob/master/react/README.md#naming)

> However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name.
We have scss + tests files in component directory, so now it looks like this:
Along with React component we keep styles + tests files side by side in component directory, so it looks like this:

```
MyComponent/
Expand All @@ -26,7 +26,7 @@ MyComponent/
|-- MyComponent.spec.jsx
```

When we'll apply airbnb rule:
With AirBnb rule applied, it looks inconsistent:

```
MyComponent/
Expand All @@ -35,18 +35,15 @@ MyComponent/
|-- MyComponent.spec.jsx
```

Kinda ugly and not consistent.

To solve this we can use this pattern:

```
MyComponent/
|-- index.jsx
|-- styles.scss
|-- specs.jsx
```
So we stick with first pattern for now.

## Ordering
[Airbnb on Ordering](https://github.com/airbnb/javascript/blob/master/react/README.md#ordering)

Ordering. I'd put all `static` methods **before** `constructor`, b/c as we are using `props` in the `constructor`, so `propTypes` should be described first. Also we use statics for transition hooks, so these methods are not related to instance methods, but `constructor` is. One more case when statics may be used is to describe some constants for component, which can also be used in `constructor`. Anyway all of these is not critical I guess.
Ordering is almost the same, except one change: we keep all `static`s **before** `constructor`.

Here is why:

* As we define `propTypes` as a [`class static properties`](https://github.com/jeffmo/es-class-fields-and-static-properties) and use `props` in the `constructor`, so `propTypes` should be described first.
* We use `static` methods as router transition hooks (especially `onEnter`), so these methods run first (before any instance is created) and in common they are not related to the instance, but `constructor` is.
* One more case when `static` may be used is to describe some constants for component, which can also be used in `constructor`.
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "shakacode-style-guide-javascript",
"version": "0.0.1",
"description": "Shakacode javascript style guide.",
"authors": [
"Justin Gordon <[email protected]> (https://github.com/justin808)",
"Alex Fedoseev <[email protected]> (https://github.com/alexfedoseev)"
],
"license": "MIT",
"repository": "https://github.com/shakacode/style-guide-javascript",
"bugs": {
"url": "https://github.com/shakacode/style-guide-javascript/issues"
},
"engines": {
"node": ">=4.2.0"
},
"scripts": {
"release:patch": "cd packages/eslint-config-shakacode && npm run release:patch",
"release:minor": "cd packages/eslint-config-shakacode && npm run release:minor",
"release:major": "cd packages/eslint-config-shakacode && npm run release:major"
}
}
31 changes: 31 additions & 0 deletions packages/eslint-config-shakacode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# eslint-config-shakacode

Shakacode `eslint` config.

## Install

```bash
npm install --save-dev eslint-config-shakacode eslint-config-airbnb eslint

# We need Babel as we use experimental features and flow syntax
npm install --save-dev babel-eslint

# If it's React project
npm install --save-dev eslint-plugin-react
```

## Use

React project:

```yml
---
extends: eslint-config-shakacode
```
Non-React project:
```yml
---
extends: eslint-config-shakacode/base
```
7 changes: 7 additions & 0 deletions packages/eslint-config-shakacode/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'parser': 'babel-eslint',
'extends': [
'eslint-config-airbnb/base',
'eslint-config-shakacode/rules/javascript',
].map(require.resolve),
};
8 changes: 8 additions & 0 deletions packages/eslint-config-shakacode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
'parser': 'babel-eslint',
'extends': [
'eslint-config-airbnb',
'eslint-config-shakacode/rules/javascript',
'eslint-config-shakacode/rules/react',
].map(require.resolve),
};
28 changes: 28 additions & 0 deletions packages/eslint-config-shakacode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "eslint-config-shakacode",
"version": "0.0.1",
"description": "Shakacode eslint config.",
"authors": [
"Justin Gordon <[email protected]> (https://github.com/justin808)",
"Alex Fedoseev <[email protected]> (https://github.com/alexfedoseev)"
],
"license": "MIT",
"repository": "https://github.com/shakacode/style-guide-javascript",
"bugs": {
"url": "https://github.com/shakacode/style-guide-javascript/issues"
},
"main": "index.js",
"engines": {
"node": ">=4.2.0"
},
"scripts": {
"release:patch": "scripts/release patch",
"release:minor": "scripts/release minor",
"release:major": "scripts/release major"
},
"peerDependencies": {
"babel-eslint": "*",
"eslint": "*",
"eslint-config-airbnb": "*"
}
}
7 changes: 7 additions & 0 deletions packages/eslint-config-shakacode/rules/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'extends': (
require
.resolve('eslint-config-shakacode')
.replace('index.js', 'rules/javascript.yml')
),
};
3 changes: 3 additions & 0 deletions packages/eslint-config-shakacode/rules/javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# In case if we'll want to override some airbnb rules
# rules:
7 changes: 7 additions & 0 deletions packages/eslint-config-shakacode/rules/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'extends': (
require
.resolve('eslint-config-shakacode')
.replace('index.js', 'rules/react.yml')
),
};
5 changes: 5 additions & 0 deletions packages/eslint-config-shakacode/rules/react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
# ES7 static is not supported yet
# See https://github.com/yannickcr/eslint-plugin-react/issues/128
react/sort-comp: 0
6 changes: 6 additions & 0 deletions packages/eslint-config-shakacode/scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

npm version $1 -m "Bump version to %s"
git push
git push --tags
npm publish

0 comments on commit 76a8167

Please sign in to comment.