Skip to content

Commit

Permalink
Cleaning up ESLint / prettier configs and uniting them (patw0929#326)
Browse files Browse the repository at this point in the history
* chore: combine prettier and eslint

* chore: clean up eslint rules

* chore: lint all

* chore: clean up lint-staged hooks
  • Loading branch information
mcataford authored Mar 8, 2020
1 parent b7f9a69 commit 9ea7769
Show file tree
Hide file tree
Showing 16 changed files with 1,523 additions and 1,269 deletions.
38 changes: 5 additions & 33 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
extends: ['eslint-config-airbnb', 'prettier'],
extends: ['eslint-config-airbnb', "plugin:prettier/recommended"],
plugins: ['react', 'import', 'security', 'prettier'],
parser: 'babel-eslint',
env: {
browser: true,
Expand All @@ -8,12 +9,14 @@ module.exports = {
jest: true,
},
rules: {
'prettier/prettier': 'error',
'prefer-destructuring': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-element-interactions': 'off',
'jsx-a11y/no-autofocus': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/anchor-has-content': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'react/destructuring-assignment': 'off',
'react/jsx-no-bind': 'error',
'react/no-multi-comp': 'off',
Expand All @@ -23,14 +26,8 @@ module.exports = {
'ForInStatement',
'WithStatement',
],
'newline-after-var': ['error', 'always'],
'newline-before-return': 'error',
'comma-dangle': ['error', 'always-multiline'], // https://github.com/airbnb/javascript/commit/788208295469e19b806c06e01095dc8ba1b6cdc9
indent: ['error', 2, { SwitchCase: 1 }],
'no-console': 0,
'no-alert': 0,
'no-underscore-dangle': 'off',
'max-len': 'off',
'react/require-default-props': 'off',
'react/jsx-curly-spacing': 'off',
'arrow-body-style': 'off',
Expand All @@ -48,9 +45,6 @@ module.exports = {
],
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx'] }],
'react/no-string-refs': 'off',
'arrow-parens': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'react/prefer-stateless-function': 'off',
'no-param-reassign': 'off',
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
'import/no-unresolved': [
Expand All @@ -62,7 +56,6 @@ module.exports = {
'error',
{
devDependencies: [
'scripts/**/*.js',
'test/**', // tape, common npm pattern
'tests/**', // also common npm pattern
'spec/**', // mocha, rspec-like pattern
Expand All @@ -80,30 +73,9 @@ module.exports = {
optionalDependencies: false,
},
],
indent: [
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
// CallExpression: {
// parameters: null,
// },
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
},
],
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
},
plugins: ['react', 'import', 'security'],

globals: {
__DEVELOPMENT__: true,
__CLIENT__: true,
Expand Down
41 changes: 18 additions & 23 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
module.exports = {
"collectCoverageFrom": [
"src/**/*.js",
"!**/__mocks__/**",
"!**/__tests__/**",
"!.storybook",
module.exports = {
collectCoverageFrom: [
'src/**/*.js',
'!**/__mocks__/**',
'!**/__tests__/**',
'!.storybook',
],
"setupFiles": [
"<rootDir>/config/jest/setup.js",
],
"setupTestFrameworkScriptFile": "<rootDir>/config/jest/setupTestFramework.js",
"testPathIgnorePatterns": [
"<rootDir>[/\\\\](build|docs|node_modules)[/\\\\]",
],
"testEnvironment": "jsdom",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/config/jest/transform.js",
"^.+\\.(scss|css)$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|css|scss|json)$)": "<rootDir>/config/jest/fileTransform.js",
setupFiles: ['<rootDir>/config/jest/setup.js'],
setupTestFrameworkScriptFile: '<rootDir>/config/jest/setupTestFramework.js',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['<rootDir>[/\\\\](build|docs|node_modules)[/\\\\]'],
testRegex: '/__tests__/.*\\.(test|spec)\\.js$',
testURL: 'http://localhost',
transform: {
'^(?!.*\\.(js|jsx|css|scss|json)$)':
'<rootDir>/config/jest/fileTransform.js',
'^.+\\.(js|jsx)$': '<rootDir>/config/jest/transform.js',
'^.+\\.(scss|css)$': '<rootDir>/config/jest/cssTransform.js',
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$",
],
"testRegex": "/__tests__/.*\\.(test|spec)\\.js$",
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
}
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@
"eslint": "^5.3.0",
"eslint-config-airbnb": "~17.1.0",
"eslint-config-airbnb-base": "~13.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-config-prettier": "^6.10.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.11.0",
"eslint-plugin-security": "^1.3.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
Expand All @@ -92,6 +93,7 @@
"packwatch": "^1.0.0",
"postcss-safe-parser": "^4.0.1",
"prettier": "^1.14.2",
"prettier-eslint": "^9.0.1",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-hot-loader": "^1.3.0",
Expand All @@ -113,12 +115,9 @@
"clean": "rimraf dist",
"start": "start-storybook -p 4000 -c .storybook",
"deploy": "storybook-to-ghpages --ci",
"lint-staged": "lint-staged",
"lint": "yarn run eslint",
"eslint": "eslint src",
"lint": "eslint src *.js",
"coverage": "yarn run test -- --coverage",
"coveralls": "cross-env NODE_ENV=development cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"prettier:all": "prettier --write 'src/components/**/*.js' 'config/**/*.js' 'scripts/**/*.js'",
"test": "jest src",
"test:watch": "jest src --watchAll --coverage",
"footprint": "yarn build && yarn packwatch",
Expand All @@ -127,21 +126,21 @@
"lint-staged": {
"linters": {
"*.js": [
"yarn prettier --write",
"yarn run eslint -- --fix",
"git add"
"yarn eslint --"
],
"src/**/*.js": [
"yarn run test -- --bail --findRelatedTests"
]
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}},
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"prettier": {
"semi": false,
"printWidth": 80,
"singleQuote": true,
"trailingComma": "es5"
Expand Down
16 changes: 8 additions & 8 deletions src/components/AllCountries.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ const defaultCountriesData = [
['Zambia', 'zm', '260'],
['Zimbabwe', 'zw', '263'],
['Åland Islands', 'ax', '358', 1],
];
]

let countries;
let countries

function _formatCountriesData(countriesData) {
return countriesData.map(country => ({
Expand All @@ -352,26 +352,26 @@ function _formatCountriesData(countriesData) {
dialCode: country[2],
priority: country[3] || 0,
areaCodes: country[4] || null,
}));
}))
}

function initialize(externalCountriesList) {
countries = _formatCountriesData(
externalCountriesList || defaultCountriesData
);
)
}

function getCountries() {
if (!countries) {
initialize();
initialize()
}

return countries;
return countries
}

const AllCountries = {
initialize,
getCountries,
};
}

export default AllCountries;
export default AllCountries
Loading

0 comments on commit 9ea7769

Please sign in to comment.