Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Last active September 13, 2017 14:44
Show Gist options
  • Save marcelmokos/a99a4db1adf841632ab2fc8daf073d75 to your computer and use it in GitHub Desktop.
Save marcelmokos/a99a4db1adf841632ab2fc8daf073d75 to your computer and use it in GitHub Desktop.
# EditorConfig: http://EditorConfig.org
# EditorConfig Properties: https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
# top-most EditorConfig file
root = true
### defaults
[*]
charset = utf-8
# Unix-style newlines with
end_of_line = lf
# 2 space indentation
indent_size = 2
indent_style = space
# remove any whitespace characters preceding newline characters
trim_trailing_whitespace = true
# newline ending every file
insert_final_newline = true
# Denotes preferred quoting style for string literals
quote_type = double
### custom for markdown
[*.md]
# do not remove any whitespace characters preceding newline characters
trim_trailing_whitespace = false
---
root: true
parser: babel-eslint
extends:
# http://eslint.org/docs/user-guide/configuring#using-eslintrecommended
- eslint:recommended
# https://github.com/gajus/eslint-plugin-flowtype
- plugin:flowtype/recommended
# https://www.npmjs.com/package/eslint-config-airbnb-base
- airbnb
# https://github.com/prettier/eslint-config-prettier
- prettier
- prettier/flowtype
- prettier/react
plugins:
- react
- import
- async-await
- jest
- flowtype
# https://github.com/prettier/eslint-plugin-prettier
- prettier
settings:
flowtype:
# with this option you do not have to add @flow in files
onlyFilesWithFlowAnnotation: false
env:
es6: true
browser: true
node: true
jasmine: true
jest: true
globals:
describe: true
it: true
fetch: true
navigator: true
__DEV__: true
XMLHttpRequest: true
parserOptions:
ecmaVersion: 2017
sourceType: module
jsx: true
rules:
### Different from airbnb config
### Styling ###
# better to ignore comments and others
max-len:
- error
-
code: 80
ignoreComments: true
ignoreTrailingComments: true
ignoreStrings: true
ignoreTemplateLiterals: true
ignoreRegExpLiterals: true
# I prefer new line before error
# http://eslint.org/docs/rules/newline-before-return
newline-before-return: error # airbnb default: off
# I prefer double quotes
# http://eslint.org/docs/rules/quotes
quotes: [error, double] # airbnb default: ['error', 'single', { avoidEscape: true }]
# enforce no padding inside curly braces
#http://eslint.org/docs/rules/object-curly-spacing
object-curly-spacing: [error, never]
### Variables ###
# Functions and classes can be used before declaration
# http://eslint.org/docs/rules/no-use-before-define
no-use-before-define: # airbnb default: error
- error
-
functions: false
classes: false
### ES6 ###
# enforce usage of spacing in template strings
# http://eslint.org/docs/rules/template-curly-spacing
template-curly-spacing: [error, never] # airbnb default: error
### Best practices ###
# require or disallow Yoda conditions
yoda: [error, never, { exceptRange: true }]
# add culry braces all the time
curly: [error, all] # airbnb default: [error, multi-line]
### Import ###
import/prefer-default-export: 0
import/first: 0
### Errors ###
no-console: 0
no-debugger: 0
### Async await ###
async-await/space-after-async: error
async-await/space-after-await: error
### React ###
# do not force jsx use js
react/jsx-filename-extension: 0
# jsx indent
react/jsx-indent:
- error
- 2
react/jsx-indent-props:
- error
- 2
# function composition over default props
react/require-default-props: 0
# put props on new line
react/jsx-first-prop-new-line: [error, multiline]
# put closing bracket on next line
react/jsx-closing-bracket-location: [error, line-aligned]
# put one property per line
react/jsx-max-props-per-line:
- error
-
maximum: 1
# Disabled because not working when used with flow prop types
react/no-unused-prop-types: 0
# render do not have use static
class-methods-use-this:
- error
-
exceptMethods:
- render
### Next.js ###
# when next.js is used react do not have be in scope
react/react-in-jsx-scope: 0
#!/bin/bash
echo "๐Ÿ”— install babel"
yarn add --dev babel-preset-react-app
echo "๐Ÿ”— add .babelrc"
echo '{
"presets": ["react-app"]
}
' > .babelrc
#!/bin/bash
gist="https://gist.githubusercontent.com/marcelmokos/a99a4db1adf841632ab2fc8daf073d75/raw"
echo "๐Ÿ”— add .editorconfig"
curl -s -H 'Cache-Control: no-cache' "$gist/.editorconfig" > .editorconfig
#!/bin/bash
echo "๐Ÿ”— install eslint"
yarn add --dev husky lint-staged
yarn add --dev eslint babel-eslint eslint-config-airbnb eslint-plugin-async-await eslint-plugin-flowtype eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-jest eslint-plugin-jsx eslint-plugin-react
yarn add --dev prettier eslint-config-prettier eslint-plugin-prettier
gist="https://gist.githubusercontent.com/marcelmokos/a99a4db1adf841632ab2fc8daf073d75/raw"
echo "๐Ÿ”— add .eslintrc.yml"
curl -s -H 'Cache-Control: no-cache' "$gist/.eslintrc.yml" > .eslintrc.yml
echo "๐Ÿ”— add .eslintignore"
echo "node_modules/**
flow-typed/**
coverage/**
.history/**
.next/**
.vscode/**
.idea/**
" > .eslintignore
#!/bin/bash
echo "๐Ÿ”— install flow"
yarn add --dev flow-bin
echo "๐Ÿ”— add .flowconfig"
echo "
[ignore]
.*/node_modules/.*
.*/.history/*
[include]
[libs]
flow-typed
[options]
emoji=true
" > .flowconfig
mkdir .vscode
echo '// Place your settings in this file to overwrite default and user settings.
{
"flow.path": "node_modules/.bin/flow",
"javascript.validate.enable": false,
"files.associations": {
"*.js": "flow"
}
}
' > .vscode/settings.json
packagejson=$(cat package.json)
addtopackagejson=$(echo '{
"scripts": {
"flow": "flow --show-all-errors",
"flow:coverage": "flow coverage ./src/index.js --color",
"flow:prepare": "flow-typed install && flow-typed update",
}
}')
echo "๐Ÿ”— add flow pre-commit hook to package.json"
echo "$addtopackagejson
$packagejson" | json --deep-merge > package.json
npm install -g flow-typed && flow-typed install
#!/bin/bash
echo "๐Ÿ”— add .gitingore"
echo "# Custom .gitingore
flow-typed
.history
.next" > .gitignore && curl -s https://www.gitignore.io/api/macos,linux,windows,node,jetbrains,sublimetext,visualstudiocode >> .gitignore
#!/bin/bash
gist="https://gist.githubusercontent.com/marcelmokos/a99a4db1adf841632ab2fc8daf073d75/raw"
echo "๐Ÿ”— $gist/install.sh"
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/gitignore.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/editorconfig.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/babel.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/eslint.sh")
yarn add react
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/packagejson.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/flow.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/jest.sh")
bash <(curl -s -H 'Cache-Control: no-cache' "$gist/nextjs.sh")
#!/bin/bash
echo "๐Ÿ”— add jest test"
yarn add --dev jest
flow-typed install jest
function init_nextjs {
yarn add next@beta isomorphic-fetch
packagejson=$(cat package.json)
addtopackagejson=$(echo '{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}')
echo "๐Ÿ”— add nextjs scripts to package.json"
echo "$addtopackagejson
$packagejson" | json --deep-merge > package.json
echo "๐Ÿ”— add nextjs .babelrc"
echo '{
"presets": [
"next/babel",
"latest",
"stage-0"
],
"plugins": [
"flow-react-proptypes",
"transform-flow-strip-types"
],
"sourceMaps": true,
"retainLines": true
}
' > .babelrc
grep -q react/react-in-jsx-scop .eslintrc.yml || echo "
### Next.js ###
# when next.js is used react do not have be in scope
react/react-in-jsx-scope: 0" >> .eslintrc.yml
mkdir api components pages static
}
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) echo "๐Ÿ”— install aborted" ; return 1 ;;
esac
done
}
yes_or_no "Do you wish to install this nextjs?" && init_nextjs
#!/bin/bash
echo "๐Ÿ”— add json -g"
npm install -g json
echo "๐Ÿ”— package.json"
# json -I -f package.json -e 'this.scripts.test="jest --env=jsdom"'
packagejson=$(cat package.json)
addtopackagejson=$(echo '{
"author": "Marcel Mokoลก <https://github.com/marcelmokos>",
"scripts": {
"test": "jest",
"test:watch": "yarn test --watch",
"test:coverage": "yarn test --coverage",
"lint": "eslint \"src/**\" --cache",
"lint:fix": "yarn lint --fix",
"lint:staged": "yarn lint:fix -- --rule 'no-console:2' --rule 'no-debugger:2'",
"precommit": "lint-staged",
"prepush": "yarn test",
},
"lint-staged": {
"*.js": [
"lint:staged",
"git add"
],
"*.{css}": [
"prettier --write",
"git add"
]
},
}')
echo "$addtopackagejson
$packagejson" | json --deep-merge > package.json
#!/bin/bash
# You can add something like this into your .bashrc or .zshrc
runGist() {
bash <(curl -s -H 'Cache-Control: no-cache' "https://gist.githubusercontent.com/marcelmokos/a99a4db1adf841632ab2fc8daf073d75/raw/$1")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment