Skip to content

Commit

Permalink
Add ESLint and Prettier (#21)
Browse files Browse the repository at this point in the history
Closes #5.
  • Loading branch information
NMinhNguyen authored Feb 28, 2020
1 parent 2e59ba1 commit 3f0abdb
Show file tree
Hide file tree
Showing 10 changed files with 1,267 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
paths:
- ~/.cache/yarn

- run: yarn lint

- run: yarn test

- run: yarn build
139 changes: 139 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
'use strict';

const restrictedGlobals = require('confusing-browser-globals');

const OFF = 'off';
const ERROR = 'error';

// Files that are transformed and can use ES6/JSX.
const esNextPaths = [
// Internal forwarding modules
'./index.js',
// Source files
'src/**/*.js',
// Jest
'scripts/jest/setupTests.js',
];

// Files that we distribute on npm that should be ES5-only.
const es5Paths = ['npm/**/*.js'];

module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'prettier/react',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'script',
},
plugins: ['react'],
settings: {
react: {
version: 'detect',
},
},
rules: {
'no-console': ERROR,
'no-empty': OFF,
'no-restricted-globals': [ERROR, ...restrictedGlobals],
'no-unsafe-finally': OFF,
'no-unused-vars': [ERROR, {args: 'none'}],
'no-useless-escape': OFF,

// We apply these settings to files that should run on Node.
// They can't use JSX or ES6 modules, and must be in strict mode.
// They can, however, use other ES6 features.
// (Note these rules are overridden later for source files.)
'no-var': ERROR,
strict: ERROR,
},
overrides: [
{
// We apply these settings to files that we ship through npm.
// They must be ES5.
files: es5Paths,
parser: 'espree',
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
},
rules: {
'no-var': OFF,
strict: ERROR,
},
overrides: [
{
// These files are ES5 but with ESM support.
files: ['npm/esm/**/*.js'],
parserOptions: {
// Although this is supposed to be 5, ESLint doesn't allow sourceType 'module' when ecmaVersion < 2015.
// See https://github.com/eslint/eslint/issues/9687#issuecomment-508448526
ecmaVersion: 2015,
sourceType: 'module',
},
},
],
},
{
// We apply these settings to the source files that get compiled.
// They can use all features including JSX (but shouldn't use `var`).
files: esNextPaths,
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'no-var': ERROR,
strict: OFF,
},
},
{
// Rollup understands ESM
files: ['rollup.config.js'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
},
{
files: ['**/__tests__/**/*.js', 'scripts/jest/setupTests.js'],
env: {
'jest/globals': true,
},
plugins: ['jest'],
rules: {
// https://github.com/jest-community/eslint-plugin-jest
'jest/no-focused-tests': ERROR,
'jest/valid-expect': ERROR,
'jest/valid-expect-in-promise': ERROR,

// React & JSX
// This isn't useful in our test code
'react/display-name': OFF,
'react/jsx-key': OFF,
'react/no-deprecated': OFF,
'react/no-string-refs': OFF,
'react/prop-types': OFF,
},
},
{
files: ['scripts/**/*.js', 'npm/**/*.js'],
rules: {
'no-console': OFF,
},
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build/
.eslintcache
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
presets: [
[
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
modulePathIgnorePatterns: ['<rootDir>/build/'],
setupFilesAfterEnv: ['./scripts/jest/setupTests.js'],
Expand Down
25 changes: 22 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/core": "^7.8.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-classes": "^7.8.3",
"@babel/plugin-transform-classes": "^7.8.6",
"@babel/plugin-transform-react-jsx-source": "^7.8.3",
"@babel/plugin-transform-template-literals": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-env": "^7.8.6",
"@babel/preset-react": "^7.8.3",
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-replace": "^2.3.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.1.0",
"confusing-browser-globals": "^1.0.9",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-jest": "^23.8.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"fs-extra": "^8.1.0",
"husky": "^4.2.3",
"jest": "^25.1.0",
"jest-diff": "^25.1.0",
"lint-staged": "^10.0.8",
"prettier": "1.19.1",
"react": "^16.12.0",
"rimraf": "^3.0.1",
"rollup": "^1.30.1",
Expand All @@ -57,7 +67,16 @@
"prebuild": "rimraf build",
"build": "rollup --config",
"postbuild": "node ./scripts/copyFiles.js",
"lint": "eslint --ignore-path .gitignore .",
"test": "jest",
"test:debug": "node --inspect-brk node_modules/jest/bin/jest.js --runInBand --no-cache"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": "eslint --cache --fix"
}
}
2 changes: 1 addition & 1 deletion src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ See https://fb.me/react-invalid-hook-call for tips about how to debug and fix th
if (process.env.NODE_ENV !== 'production') {
ReactDebugCurrentFrame.getCurrentStack = prevGetStack;
}
}
}

this._rendering = false;
this._updater._invokeCallbacks();
Expand Down
6 changes: 4 additions & 2 deletions src/shared/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import React from 'react';
const ReactSharedInternals =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

const hasOwnProperty = Object.prototype.hasOwnProperty;

// Prevent newer renderers from RTE when used with older react package versions.
// Current owner and dispatcher used to share the same ref,
// but PR #14548 split them out to better support the react-debug-tools package.
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
if (!hasOwnProperty.call(ReactSharedInternals, 'ReactCurrentDispatcher')) {
ReactSharedInternals.ReactCurrentDispatcher = {
current: null,
};
}
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
if (!hasOwnProperty.call(ReactSharedInternals, 'ReactCurrentBatchConfig')) {
ReactSharedInternals.ReactCurrentBatchConfig = {
suspense: null,
};
Expand Down
1 change: 1 addition & 0 deletions src/shared/consoleWithStackDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function printWarning(level, format, args) {
argsWithFormat.unshift('Warning: ' + format);
// We intentionally don't use spread (or .apply) directly because it
// breaks IE9: https://github.com/facebook/react/issues/13610
// eslint-disable-next-line no-console
Function.prototype.apply.call(console[level], console, argsWithFormat);

try {
Expand Down
Loading

0 comments on commit 3f0abdb

Please sign in to comment.