Fix prettier on all files

This commit is contained in:
2019-08-03 20:40:07 +05:30
parent feee690b48
commit 67206dfe41
24 changed files with 164 additions and 144 deletions
+16 -16
View File
@@ -1,37 +1,37 @@
module.exports = { module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', parser: "@typescript-eslint/parser",
parserOptions: { parserOptions: {
project: 'tsconfig.json', project: "tsconfig.json",
sourceType: 'module', sourceType: "module",
ecmaFeatures: { ecmaFeatures: {
jsx: true jsx: true
} }
}, },
settings: { settings: {
react: { react: {
version: 'detect' version: "detect"
} }
}, },
extends: [ extends: [
'plugin:react/recommended', "plugin:react/recommended",
'plugin:@typescript-eslint/recommended', "plugin:@typescript-eslint/recommended",
'prettier', "prettier",
'prettier/@typescript-eslint' "prettier/@typescript-eslint"
], ],
plugins: ['react', 'react-hooks', '@typescript-eslint'], plugins: ["react", "react-hooks", "@typescript-eslint"],
rules: { rules: {
'@typescript-eslint/explicit-function-return-type': 'off', "@typescript-eslint/explicit-function-return-type": "off",
'@typescript-eslint/explicit-member-accessibility': 'off', "@typescript-eslint/explicit-member-accessibility": "off",
'react-hooks/exhaustive-deps': 'warn', "react-hooks/exhaustive-deps": "warn",
'react-hooks/rules-of-hooks': 'error' "react-hooks/rules-of-hooks": "error"
}, },
overrides: [ overrides: [
{ {
files: ['*.js'], files: ["*.js"],
rules: { rules: {
'@typescript-eslint/no-var-requires': 'off' "@typescript-eslint/no-var-requires": "off"
} }
} }
] ]
} };
+1 -1
View File
@@ -2,5 +2,5 @@ language: node_js
notifications: notifications:
email: false email: false
script: script:
- npm t - npm run test
- $(npm bin)/codecov - $(npm bin)/codecov
+4 -4
View File
@@ -1,5 +1,5 @@
import C from 'react-fiber-traverse' import C from "react-fiber-traverse";
import React from 'react' import React from "react";
import ReactDOM from 'react-dom' import ReactDOM from "react-dom";
ReactDOM.render(<C />, document.getElementById('root')) ReactDOM.render(<C />, document.getElementById("root"));
+4 -4
View File
@@ -1,7 +1,7 @@
'use strict' "use strict";
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === "production") {
module.exports = require('./react-fiber-traverse.cjs.production.js') module.exports = require("./react-fiber-traverse.cjs.production.js");
} else { } else {
module.exports = require('./react-fiber-traverse.cjs.development.js') module.exports = require("./react-fiber-traverse.cjs.development.js");
} }
+1
View File
@@ -15,6 +15,7 @@
"bundle": "rollup -c", "bundle": "rollup -c",
"changelog": "github_changelog_generator --no-issues --header-label \"# Changelog\" --future-release v$npm_package_version", "changelog": "github_changelog_generator --no-issues --header-label \"# Changelog\" --future-release v$npm_package_version",
"check:format": "prettier --list-different \"**/*.{js,ts,tsx}\"", "check:format": "prettier --list-different \"**/*.{js,ts,tsx}\"",
"fix:format": "prettier --write \"**/*.{js,ts,tsx}\"",
"check:types": "tsc --noEmit", "check:types": "tsc --noEmit",
"clean": "run-p clean:*", "clean": "run-p clean:*",
"clean:compiled": "del compiled", "clean:compiled": "del compiled",
+74 -74
View File
@@ -1,72 +1,72 @@
import babel from 'rollup-plugin-babel' import babel from "rollup-plugin-babel";
import commonjs from 'rollup-plugin-commonjs' import commonjs from "rollup-plugin-commonjs";
import nodeResolve from 'rollup-plugin-node-resolve' import nodeResolve from "rollup-plugin-node-resolve";
import replace from 'rollup-plugin-replace' import replace from "rollup-plugin-replace";
import { sizeSnapshot } from 'rollup-plugin-size-snapshot' import { sizeSnapshot } from "rollup-plugin-size-snapshot";
import sourcemaps from 'rollup-plugin-sourcemaps' import sourcemaps from "rollup-plugin-sourcemaps";
import { terser } from 'rollup-plugin-terser' import { terser } from "rollup-plugin-terser";
import pkg from './package.json' import pkg from "./package.json";
const CJS_DEV = 'CJS_DEV' const CJS_DEV = "CJS_DEV";
const CJS_PROD = 'CJS_PROD' const CJS_PROD = "CJS_PROD";
const ES = 'ES' const ES = "ES";
const UMD_DEV = 'UMD_DEV' const UMD_DEV = "UMD_DEV";
const UMD_PROD = 'UMD_PROD' const UMD_PROD = "UMD_PROD";
const input = './compiled/index.js' const input = "./compiled/index.js";
const getGlobals = bundleType => { const getGlobals = bundleType => {
const baseGlobals = { const baseGlobals = {
'react-dom': 'ReactDOM', "react-dom": "ReactDOM",
react: 'React' react: "React"
} };
switch (bundleType) { switch (bundleType) {
case UMD_DEV: case UMD_DEV:
return { ...baseGlobals, 'prop-types': 'PropTypes' } return { ...baseGlobals, "prop-types": "PropTypes" };
case UMD_PROD: case UMD_PROD:
return baseGlobals return baseGlobals;
default: default:
return {} return {};
}
} }
};
const getExternal = bundleType => { const getExternal = bundleType => {
const peerDependencies = Object.keys(pkg.peerDependencies) const peerDependencies = Object.keys(pkg.peerDependencies);
const dependencies = Object.keys(pkg.dependencies) const dependencies = Object.keys(pkg.dependencies);
// Hat-tip: https://github.com/rollup/rollup-plugin-babel/issues/148#issuecomment-399696316. // Hat-tip: https://github.com/rollup/rollup-plugin-babel/issues/148#issuecomment-399696316.
const makeExternalPredicate = externals => { const makeExternalPredicate = externals => {
if (externals.length === 0) { if (externals.length === 0) {
return () => false return () => false;
}
const pattern = new RegExp(`^(${externals.join('|')})($|/)`)
return id => pattern.test(id)
} }
const pattern = new RegExp(`^(${externals.join("|")})($|/)`);
return id => pattern.test(id);
};
switch (bundleType) { switch (bundleType) {
case CJS_DEV: case CJS_DEV:
case CJS_PROD: case CJS_PROD:
case ES: case ES:
return makeExternalPredicate([...peerDependencies, ...dependencies]) return makeExternalPredicate([...peerDependencies, ...dependencies]);
case UMD_DEV: case UMD_DEV:
return makeExternalPredicate([...peerDependencies, 'prop-types']) return makeExternalPredicate([...peerDependencies, "prop-types"]);
default: default:
return makeExternalPredicate(peerDependencies) return makeExternalPredicate(peerDependencies);
}
} }
};
const isProduction = bundleType => const isProduction = bundleType =>
bundleType === CJS_PROD || bundleType === UMD_PROD bundleType === CJS_PROD || bundleType === UMD_PROD;
const getBabelConfig = bundleType => { const getBabelConfig = bundleType => {
const options = { const options = {
babelrc: false, babelrc: false,
exclude: 'node_modules/**', exclude: "node_modules/**",
presets: [['@babel/env', { loose: true, modules: false }], '@babel/react'], presets: [["@babel/env", { loose: true, modules: false }], "@babel/react"],
plugins: ['@babel/transform-runtime'], plugins: ["@babel/transform-runtime"],
runtimeHelpers: true runtimeHelpers: true
} };
switch (bundleType) { switch (bundleType) {
case ES: case ES:
@@ -74,53 +74,53 @@ const getBabelConfig = bundleType => {
...options, ...options,
plugins: [ plugins: [
...options.plugins, ...options.plugins,
['transform-react-remove-prop-types', { mode: 'wrap' }] ["transform-react-remove-prop-types", { mode: "wrap" }]
] ]
} };
case UMD_PROD: case UMD_PROD:
case CJS_PROD: case CJS_PROD:
return { return {
...options, ...options,
plugins: [ plugins: [
...options.plugins, ...options.plugins,
['transform-react-remove-prop-types', { removeImport: true }] ["transform-react-remove-prop-types", { removeImport: true }]
] ]
} };
default: default:
return options return options;
}
} }
};
const getPlugins = bundleType => [ const getPlugins = bundleType => [
nodeResolve(), nodeResolve(),
commonjs({ commonjs({
include: 'node_modules/**', include: "node_modules/**",
namedExports: { namedExports: {
'node_modules/prop-types/index.js': [ "node_modules/prop-types/index.js": [
'any', "any",
'array', "array",
'arrayOf', "arrayOf",
'bool', "bool",
'element', "element",
'exact', "exact",
'func', "func",
'instanceOf', "instanceOf",
'node', "node",
'number', "number",
'object', "object",
'objectOf', "objectOf",
'oneOf', "oneOf",
'oneOfType', "oneOfType",
'shape', "shape",
'string', "string",
'symbol' "symbol"
] ]
} }
}), }),
babel(getBabelConfig(bundleType)), babel(getBabelConfig(bundleType)),
replace({ replace({
'process.env.NODE_ENV': JSON.stringify( "process.env.NODE_ENV": JSON.stringify(
isProduction(bundleType) ? 'production' : 'development' isProduction(bundleType) ? "production" : "development"
) )
}), }),
sourcemaps(), sourcemaps(),
@@ -137,46 +137,46 @@ const getPlugins = bundleType => [
ecma: 5, ecma: 5,
toplevel: false toplevel: false
}) })
] ];
const getCjsConfig = bundleType => ({ const getCjsConfig = bundleType => ({
input, input,
external: getExternal(bundleType), external: getExternal(bundleType),
output: { output: {
file: `dist/react-fiber-traverse.cjs.${ file: `dist/react-fiber-traverse.cjs.${
isProduction(bundleType) ? 'production' : 'development' isProduction(bundleType) ? "production" : "development"
}.js`, }.js`,
format: 'cjs', format: "cjs",
sourcemap: true sourcemap: true
}, },
plugins: getPlugins(bundleType) plugins: getPlugins(bundleType)
}) });
const getEsConfig = () => ({ const getEsConfig = () => ({
input, input,
external: getExternal(ES), external: getExternal(ES),
output: { output: {
file: pkg.module, file: pkg.module,
format: 'es', format: "es",
sourcemap: true sourcemap: true
}, },
plugins: getPlugins(ES) plugins: getPlugins(ES)
}) });
const getUmdConfig = bundleType => ({ const getUmdConfig = bundleType => ({
input, input,
external: getExternal(bundleType), external: getExternal(bundleType),
output: { output: {
file: `dist/react-fiber-traverse.umd.${ file: `dist/react-fiber-traverse.umd.${
isProduction(bundleType) ? 'production' : 'development' isProduction(bundleType) ? "production" : "development"
}.js`, }.js`,
format: 'umd', format: "umd",
globals: getGlobals(bundleType), globals: getGlobals(bundleType),
name: 'reactFiberTraverse', name: "reactFiberTraverse",
sourcemap: true sourcemap: true
}, },
plugins: getPlugins(bundleType) plugins: getPlugins(bundleType)
}) });
export default [ export default [
getCjsConfig(CJS_DEV), getCjsConfig(CJS_DEV),
@@ -184,4 +184,4 @@ export default [
getEsConfig(), getEsConfig(),
getUmdConfig(UMD_DEV), getUmdConfig(UMD_DEV),
getUmdConfig(UMD_PROD) getUmdConfig(UMD_PROD)
] ];
+3 -3
View File
@@ -1,8 +1,8 @@
const srcConfig = require('./config.src') const srcConfig = require("./config.src");
module.exports = Object.assign({}, srcConfig, { module.exports = Object.assign({}, srcConfig, {
collectCoverage: false, collectCoverage: false,
moduleNameMapper: { moduleNameMapper: {
'^../src$': `<rootDir>/dist/index.js` "^../src$": `<rootDir>/dist/index.js`
} }
}) });
+3 -3
View File
@@ -1,8 +1,8 @@
const srcConfig = require('./config.src') const srcConfig = require("./config.src");
module.exports = Object.assign({}, srcConfig, { module.exports = Object.assign({}, srcConfig, {
collectCoverage: false, collectCoverage: false,
moduleNameMapper: { moduleNameMapper: {
'^../src$': `<rootDir>/dist/react-fiber-traverse.esm.js` "^../src$": `<rootDir>/dist/react-fiber-traverse.esm.js`
} }
}) });
+9 -9
View File
@@ -1,12 +1,12 @@
module.exports = { module.exports = {
collectCoverage: true, collectCoverage: true,
collectCoverageFrom: ['src/*.{ts,tsx}'], collectCoverageFrom: ["src/*.{ts,tsx}"],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], moduleFileExtensions: ["ts", "tsx", "js", "json"],
preset: 'ts-jest', preset: "ts-jest",
rootDir: process.cwd(), rootDir: process.cwd(),
roots: ['<rootDir>/test'], roots: ["<rootDir>/test"],
setupFiles: ['<rootDir>/scripts/jest/setupEnvironment.ts'], setupFiles: ["<rootDir>/scripts/jest/setupEnvironment.ts"],
setupFilesAfterEnv: ['<rootDir>/scripts/jest/setupJest.ts'], setupFilesAfterEnv: ["<rootDir>/scripts/jest/setupJest.ts"],
testMatch: ['<rootDir>/test/*.spec.ts?(x)'], testMatch: ["<rootDir>/test/*.spec.ts?(x)"],
transform: { '^.+\\.(js|tsx?)$': 'ts-jest' } transform: { "^.+\\.(js|tsx?)$": "ts-jest" }
} };
+3 -3
View File
@@ -1,8 +1,8 @@
const srcConfig = require('./config.src') const srcConfig = require("./config.src");
module.exports = Object.assign({}, srcConfig, { module.exports = Object.assign({}, srcConfig, {
collectCoverage: false, collectCoverage: false,
moduleNameMapper: { moduleNameMapper: {
'^../src$': `<rootDir>/dist/react-fiber-traverse.umd.development.js` "^../src$": `<rootDir>/dist/react-fiber-traverse.umd.development.js`
} }
}) });
+3 -3
View File
@@ -1,8 +1,8 @@
const srcConfig = require('./config.src') const srcConfig = require("./config.src");
module.exports = Object.assign({}, srcConfig, { module.exports = Object.assign({}, srcConfig, {
collectCoverage: false, collectCoverage: false,
moduleNameMapper: { moduleNameMapper: {
'^../src$': `<rootDir>/dist/react-fiber-traverse.umd.production.js` "^../src$": `<rootDir>/dist/react-fiber-traverse.umd.production.js`
} }
}) });
+3 -3
View File
@@ -1,4 +1,4 @@
import { configure } from 'enzyme' import { configure } from "enzyme";
import Adapter from 'enzyme-adapter-react-16' import Adapter from "enzyme-adapter-react-16";
configure({ adapter: new Adapter() }) configure({ adapter: new Adapter() });
+2 -2
View File
@@ -1,4 +1,4 @@
import { createPrettyHtmlMatchers } from 'jest-prettyhtml-matchers' import { createPrettyHtmlMatchers } from "jest-prettyhtml-matchers";
expect.extend( expect.extend(
createPrettyHtmlMatchers({ createPrettyHtmlMatchers({
@@ -6,4 +6,4 @@ expect.extend(
sortAttributes: true, sortAttributes: true,
wrapAttributes: true wrapAttributes: true
}) })
) );
+8 -2
View File
@@ -48,7 +48,10 @@ function findNodeByComponent(
} }
} }
{ {
const returnVal = findNodeByComponent(node.sibling, expectedClassOrFunction); const returnVal = findNodeByComponent(
node.sibling,
expectedClassOrFunction
);
if (returnVal !== null) { if (returnVal !== null) {
return returnVal; return returnVal;
} }
@@ -76,7 +79,10 @@ function findNodeByComponentRef(
} }
} }
{ {
const returnVal = findNodeByComponentRef(node.sibling, expectedClassInstance); const returnVal = findNodeByComponentRef(
node.sibling,
expectedClassInstance
);
if (returnVal !== null) { if (returnVal !== null) {
return returnVal; return returnVal;
} }
+8 -2
View File
@@ -1,6 +1,10 @@
import * as React from "react"; import * as React from "react";
export type FiberNode = FiberNodeForComponentClass | FiberNodeForFunctionComponent | FiberNodeForInstrinsicElement | FiberNodeForTextNode; export type FiberNode =
| FiberNodeForComponentClass
| FiberNodeForFunctionComponent
| FiberNodeForInstrinsicElement
| FiberNodeForTextNode;
export interface FiberNodeForFunctionComponent { export interface FiberNodeForFunctionComponent {
child: FiberNode | null; child: FiberNode | null;
@@ -52,4 +56,6 @@ export interface FiberNodeForTextNode {
stateNode: Text; stateNode: Text;
} }
export type FiberNodeisHTMLLike = FiberNodeForInstrinsicElement | FiberNodeForTextNode; export type FiberNodeisHTMLLike =
| FiberNodeForInstrinsicElement
| FiberNodeForTextNode;
+3 -1
View File
@@ -52,7 +52,9 @@ function* traverseGenerator(
}; };
// For each item mentioned in order, find generator functions to run // For each item mentioned in order, find generator functions to run
const orderedGenerators = order.map((step) => traverseMap[step]).filter(tmp => tmp!==undefined); const orderedGenerators = order
.map(step => traverseMap[step])
.filter(tmp => tmp !== undefined);
// Now run each generator till end // Now run each generator till end
for (const eachGen of orderedGenerators) { for (const eachGen of orderedGenerators) {
+3 -1
View File
@@ -28,7 +28,9 @@ function isNodeComponentClass(
return isNodeNotHtmlLike(node) && node.stateNode instanceof React.Component; return isNodeNotHtmlLike(node) && node.stateNode instanceof React.Component;
} }
function isConstructorHtmlLike(ctr: React.ElementType): ctr is Exclude<React.ElementType, React.ComponentType> { function isConstructorHtmlLike(
ctr: React.ElementType
): ctr is Exclude<React.ElementType, React.ComponentType> {
if (typeof ctr === "string" || ctr === null) { if (typeof ctr === "string" || ctr === null) {
return true; return true;
} }
+1 -1
View File
@@ -17,7 +17,7 @@ describe("Component", () => {
it("should render correctly", () => { it("should render correctly", () => {
const rootRef = React.createRef<C>(); const rootRef = React.createRef<C>();
rootRef.current && rootRef.current rootRef.current && rootRef.current;
wrapper = mount(<C text="text" ref={rootRef} />, { attachTo: container }); wrapper = mount(<C text="text" ref={rootRef} />, { attachTo: container });
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
+7 -2
View File
@@ -85,7 +85,7 @@ describe("findNodeByComponentName", () => {
const rootNode = mountAndGetRootNode(WrappedC, container); const rootNode = mountAndGetRootNode(WrappedC, container);
const foundFnDepth1 = findNodeByComponentName(rootNode, FnDepth1.name); const foundFnDepth1 = findNodeByComponentName(rootNode, FnDepth1.name);
const foundInner = findNodeByComponentName(foundFnDepth1, 'someName'); const foundInner = findNodeByComponentName(foundFnDepth1, "someName");
expect(foundInner).toBeFalsy(); expect(foundInner).toBeFalsy();
expect(foundInner).toBe(null); expect(foundInner).toBe(null);
@@ -96,7 +96,12 @@ describe("findNodeByComponentName", () => {
return <Fn2 />; return <Fn2 />;
} }
function Fn2() { function Fn2() {
return <div>Fn2 here<Fn3/></div>; return (
<div>
Fn2 here
<Fn3 />
</div>
);
} }
function Fn3() { function Fn3() {
return <div>Fn3 here</div>; return <div>Fn3 here</div>;
+1 -1
View File
@@ -13,7 +13,7 @@ import { mountAndGetRootNode } from "./utils/mountInEnzyme";
import CDepth1 from "./sample-components/depth-1-simple"; import CDepth1 from "./sample-components/depth-1-simple";
import CDepth2 from "./sample-components/depth-2-simple"; import CDepth2 from "./sample-components/depth-2-simple";
import CDepth5 from "./sample-components/depth-5-simple"; import CDepth5 from "./sample-components/depth-5-simple";
import FnDepth1 from './sample-components/depth-1-fn-simple'; import FnDepth1 from "./sample-components/depth-1-fn-simple";
describe("traverseGenerator", () => { describe("traverseGenerator", () => {
let container: HTMLDivElement; let container: HTMLDivElement;
+2 -2
View File
@@ -9,7 +9,7 @@ function createFunctionComponent(name?: string): React.FunctionComponent {
if (props.children !== undefined) { if (props.children !== undefined) {
return <React.Fragment>{props.children}</React.Fragment>; return <React.Fragment>{props.children}</React.Fragment>;
} else { } else {
return null return null;
} }
}; };
@@ -31,7 +31,7 @@ function createClassComponent(name?: string): React.ComponentClass {
if (this.props.children !== undefined) { if (this.props.children !== undefined) {
return this.props.children; return this.props.children;
} else { } else {
return null return null;
} }
} }
}; };
+1 -3
View File
@@ -1,9 +1,7 @@
import * as React from "react"; import * as React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { FiberNode, FiberNodeForComponentClass } from "../../src/mocked-types"; import { FiberNode, FiberNodeForComponentClass } from "../../src/mocked-types";
import { import { isConstructorFunctionComponent } from "../../src/utils";
isConstructorFunctionComponent
} from "../../src/utils";
import getWrappedComponent from "./getWrappedComponent"; import getWrappedComponent from "./getWrappedComponent";
export class RootNodeNotFoundError extends Error { export class RootNodeNotFoundError extends Error {