Skip to content

Commit

Permalink
Dx/add prettier code (forem#188)
Browse files Browse the repository at this point in the history
* Added prettier for front-end code formatting.

* Prettier runs on JSX too now

Modified supported extensions for running prettier.

* Added some documentation in the README about prettier, husky and lint-staged.

* package-lock.json updated.

* Keep lint-staged package-manager agnostic (forem#196)

* Remove code-breaking comma
  • Loading branch information
nickytonline authored and benhalpern committed Apr 9, 2018
1 parent f0b3e65 commit d67c243
Show file tree
Hide file tree
Showing 10 changed files with 3,228 additions and 97 deletions.
13 changes: 7 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
"extends": "airbnb-base/legacy",
"env": {
"browser": true,
extends: ['airbnb-base/legacy', 'prettier'],
parserOptions: {
ecmaVersion: 6,
},
"plugins": [
"ignore-erb"
]
env: {
browser: true,
},
plugins: ['ignore-erb'],
};
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
package-lock.json
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"waderyan.nodejs-extension-pack",
"esbenp.prettier-vscode",
"donjayamanne.git-extension-pack"
]
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ Caveat: `bin/rspec` is not equipped with Spring because it affect Simplecov's re

This project follows [Bbatsov's Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide), using [Rubocop](https://github.com/bbatsov/rubocop) along with [Rubocop-Rspec](https://github.com/backus/rubocop-rspec) as the code analyzer. If you have Rubocop installed with your text editor of choice, you should be up and running. Settings can be edited in `.rubocop.yml`.

For Javascript, we follow [Airbnb's JS Style Guide](https://github.com/airbnb/javascript), using [ESLint](https://eslint.org/). If you have ESLint installed with your text editor of choice, you should be up and running.
For Javascript, we follow [Airbnb's JS Style Guide](https://github.com/airbnb/javascript), using [ESLint](https://eslint.org/) and [prettier](https://github.com/prettier/prettier). If you have ESLint installed with your text editor of choice, you should be up and running.

When commits are made, a git precommit hook runs via [husky](https://github.com/typicode/husky) and [lint-staged](https://github.com/okonet/lint-staged) on front-end code that will run eslint and prettier on your code before committing it. If there are linting errors and eslint isn't able to automatically fix it, the commit will not happen. You will need to fix the issue manually then attempt to commit again.

Note: if you've already installed the [husky](https://github.com/typicode/husky) package at least once (used for precommit npm script), you will need to run `yarn --force` or `npm install --no-cache`. For some reason the post-install script of husky does not run, when the package is pulled from yarn's or npm's cache. This is not husky specific, but rather a cached package specific issue.

## Testing
The following technologies are used for testing:
Expand Down
26 changes: 19 additions & 7 deletions app/javascript/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
module.exports = {
"extends": "airbnb",
"settings": {
"react": {
"pragma": "h"
extends: ['airbnb', 'prettier'],
parserOptions: {
ecmaVersion: 6,
},
settings: {
react: {
pragma: 'h',
},
},
"env": {
"jest": true,
"browser": true,
env: {
jest: true,
browser: true,
},
plugins: ['import'],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/*.test.js', '**/*.test.jsx', '**/*.stories.jsx'],
},
],
},
};
13 changes: 0 additions & 13 deletions app/javascript/stories/index.stories.js

This file was deleted.

19 changes: 19 additions & 0 deletions app/javascript/stories/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { h } from 'preact';

import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';

import { Button, Welcome } from '@storybook/react/demo';

storiesOf('Welcome', module).add('to Storybook', () => (
<Welcome showApp={linkTo('Button')} />
));

storiesOf('Button', module)
.add('with text', () => (
<Button onClick={action('clicked')}>Hello Button</Button>
))
.add('with some emoji', () => (
<Button onClick={action('clicked')}>😀 😎 👍 💯</Button>
));
Loading

0 comments on commit d67c243

Please sign in to comment.