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 = {
root: true,
parser: '@typescript-eslint/parser',
parser: "@typescript-eslint/parser",
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
project: "tsconfig.json",
sourceType: "module",
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: 'detect'
version: "detect"
}
},
extends: [
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint'
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
plugins: ['react', 'react-hooks', '@typescript-eslint'],
plugins: ["react", "react-hooks", "@typescript-eslint"],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'react-hooks/exhaustive-deps': 'warn',
'react-hooks/rules-of-hooks': 'error'
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error"
},
overrides: [
{
files: ['*.js'],
files: ["*.js"],
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:
email: false
script:
- npm t
- npm run test
- $(npm bin)/codecov
+4 -4
View File
@@ -1,5 +1,5 @@
import C from 'react-fiber-traverse'
import React from 'react'
import ReactDOM from 'react-dom'
import C from "react-fiber-traverse";
import React from "react";
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') {
module.exports = require('./react-fiber-traverse.cjs.production.js')
if (process.env.NODE_ENV === "production") {
module.exports = require("./react-fiber-traverse.cjs.production.js");
} 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",
"changelog": "github_changelog_generator --no-issues --header-label \"# Changelog\" --future-release v$npm_package_version",
"check:format": "prettier --list-different \"**/*.{js,ts,tsx}\"",
"fix:format": "prettier --write \"**/*.{js,ts,tsx}\"",
"check:types": "tsc --noEmit",
"clean": "run-p clean:*",
"clean:compiled": "del compiled",
+74 -74
View File
@@ -1,72 +1,72 @@
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import nodeResolve from 'rollup-plugin-node-resolve'
import replace from 'rollup-plugin-replace'
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
import sourcemaps from 'rollup-plugin-sourcemaps'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import nodeResolve from "rollup-plugin-node-resolve";
import replace from "rollup-plugin-replace";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
import sourcemaps from "rollup-plugin-sourcemaps";
import { terser } from "rollup-plugin-terser";
import pkg from "./package.json";
const CJS_DEV = 'CJS_DEV'
const CJS_PROD = 'CJS_PROD'
const ES = 'ES'
const UMD_DEV = 'UMD_DEV'
const UMD_PROD = 'UMD_PROD'
const CJS_DEV = "CJS_DEV";
const CJS_PROD = "CJS_PROD";
const ES = "ES";
const UMD_DEV = "UMD_DEV";
const UMD_PROD = "UMD_PROD";
const input = './compiled/index.js'
const input = "./compiled/index.js";
const getGlobals = bundleType => {
const baseGlobals = {
'react-dom': 'ReactDOM',
react: 'React'
}
"react-dom": "ReactDOM",
react: "React"
};
switch (bundleType) {
case UMD_DEV:
return { ...baseGlobals, 'prop-types': 'PropTypes' }
return { ...baseGlobals, "prop-types": "PropTypes" };
case UMD_PROD:
return baseGlobals
return baseGlobals;
default:
return {}
return {};
}
}
};
const getExternal = bundleType => {
const peerDependencies = Object.keys(pkg.peerDependencies)
const dependencies = Object.keys(pkg.dependencies)
const peerDependencies = Object.keys(pkg.peerDependencies);
const dependencies = Object.keys(pkg.dependencies);
// Hat-tip: https://github.com/rollup/rollup-plugin-babel/issues/148#issuecomment-399696316.
const makeExternalPredicate = externals => {
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) {
case CJS_DEV:
case CJS_PROD:
case ES:
return makeExternalPredicate([...peerDependencies, ...dependencies])
return makeExternalPredicate([...peerDependencies, ...dependencies]);
case UMD_DEV:
return makeExternalPredicate([...peerDependencies, 'prop-types'])
return makeExternalPredicate([...peerDependencies, "prop-types"]);
default:
return makeExternalPredicate(peerDependencies)
return makeExternalPredicate(peerDependencies);
}
}
};
const isProduction = bundleType =>
bundleType === CJS_PROD || bundleType === UMD_PROD
bundleType === CJS_PROD || bundleType === UMD_PROD;
const getBabelConfig = bundleType => {
const options = {
babelrc: false,
exclude: 'node_modules/**',
presets: [['@babel/env', { loose: true, modules: false }], '@babel/react'],
plugins: ['@babel/transform-runtime'],
exclude: "node_modules/**",
presets: [["@babel/env", { loose: true, modules: false }], "@babel/react"],
plugins: ["@babel/transform-runtime"],
runtimeHelpers: true
}
};
switch (bundleType) {
case ES:
@@ -74,53 +74,53 @@ const getBabelConfig = bundleType => {
...options,
plugins: [
...options.plugins,
['transform-react-remove-prop-types', { mode: 'wrap' }]
["transform-react-remove-prop-types", { mode: "wrap" }]
]
}
};
case UMD_PROD:
case CJS_PROD:
return {
...options,
plugins: [
...options.plugins,
['transform-react-remove-prop-types', { removeImport: true }]
["transform-react-remove-prop-types", { removeImport: true }]
]
}
};
default:
return options
return options;
}
}
};
const getPlugins = bundleType => [
nodeResolve(),
commonjs({
include: 'node_modules/**',
include: "node_modules/**",
namedExports: {
'node_modules/prop-types/index.js': [
'any',
'array',
'arrayOf',
'bool',
'element',
'exact',
'func',
'instanceOf',
'node',
'number',
'object',
'objectOf',
'oneOf',
'oneOfType',
'shape',
'string',
'symbol'
"node_modules/prop-types/index.js": [
"any",
"array",
"arrayOf",
"bool",
"element",
"exact",
"func",
"instanceOf",
"node",
"number",
"object",
"objectOf",
"oneOf",
"oneOfType",
"shape",
"string",
"symbol"
]
}
}),
babel(getBabelConfig(bundleType)),
replace({
'process.env.NODE_ENV': JSON.stringify(
isProduction(bundleType) ? 'production' : 'development'
"process.env.NODE_ENV": JSON.stringify(
isProduction(bundleType) ? "production" : "development"
)
}),
sourcemaps(),
@@ -137,46 +137,46 @@ const getPlugins = bundleType => [
ecma: 5,
toplevel: false
})
]
];
const getCjsConfig = bundleType => ({
input,
external: getExternal(bundleType),
output: {
file: `dist/react-fiber-traverse.cjs.${
isProduction(bundleType) ? 'production' : 'development'
isProduction(bundleType) ? "production" : "development"
}.js`,
format: 'cjs',
format: "cjs",
sourcemap: true
},
plugins: getPlugins(bundleType)
})
});
const getEsConfig = () => ({
input,
external: getExternal(ES),
output: {
file: pkg.module,
format: 'es',
format: "es",
sourcemap: true
},
plugins: getPlugins(ES)
})
});
const getUmdConfig = bundleType => ({
input,
external: getExternal(bundleType),
output: {
file: `dist/react-fiber-traverse.umd.${
isProduction(bundleType) ? 'production' : 'development'
isProduction(bundleType) ? "production" : "development"
}.js`,
format: 'umd',
format: "umd",
globals: getGlobals(bundleType),
name: 'reactFiberTraverse',
name: "reactFiberTraverse",
sourcemap: true
},
plugins: getPlugins(bundleType)
})
});
export default [
getCjsConfig(CJS_DEV),
@@ -184,4 +184,4 @@ export default [
getEsConfig(),
getUmdConfig(UMD_DEV),
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, {
collectCoverage: false,
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, {
collectCoverage: false,
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 = {
collectCoverage: true,
collectCoverageFrom: ['src/*.{ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
preset: 'ts-jest',
collectCoverageFrom: ["src/*.{ts,tsx}"],
moduleFileExtensions: ["ts", "tsx", "js", "json"],
preset: "ts-jest",
rootDir: process.cwd(),
roots: ['<rootDir>/test'],
setupFiles: ['<rootDir>/scripts/jest/setupEnvironment.ts'],
setupFilesAfterEnv: ['<rootDir>/scripts/jest/setupJest.ts'],
testMatch: ['<rootDir>/test/*.spec.ts?(x)'],
transform: { '^.+\\.(js|tsx?)$': 'ts-jest' }
}
roots: ["<rootDir>/test"],
setupFiles: ["<rootDir>/scripts/jest/setupEnvironment.ts"],
setupFilesAfterEnv: ["<rootDir>/scripts/jest/setupJest.ts"],
testMatch: ["<rootDir>/test/*.spec.ts?(x)"],
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, {
collectCoverage: false,
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, {
collectCoverage: false,
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 Adapter from 'enzyme-adapter-react-16'
import { configure } from "enzyme";
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(
createPrettyHtmlMatchers({
@@ -6,4 +6,4 @@ expect.extend(
sortAttributes: 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) {
return returnVal;
}
@@ -76,7 +79,10 @@ function findNodeByComponentRef(
}
}
{
const returnVal = findNodeByComponentRef(node.sibling, expectedClassInstance);
const returnVal = findNodeByComponentRef(
node.sibling,
expectedClassInstance
);
if (returnVal !== null) {
return returnVal;
}
+8 -2
View File
@@ -1,6 +1,10 @@
import * as React from "react";
export type FiberNode = FiberNodeForComponentClass | FiberNodeForFunctionComponent | FiberNodeForInstrinsicElement | FiberNodeForTextNode;
export type FiberNode =
| FiberNodeForComponentClass
| FiberNodeForFunctionComponent
| FiberNodeForInstrinsicElement
| FiberNodeForTextNode;
export interface FiberNodeForFunctionComponent {
child: FiberNode | null;
@@ -52,4 +56,6 @@ export interface FiberNodeForTextNode {
stateNode: Text;
}
export type FiberNodeisHTMLLike = FiberNodeForInstrinsicElement | FiberNodeForTextNode;
export type FiberNodeisHTMLLike =
| FiberNodeForInstrinsicElement
| FiberNodeForTextNode;
+4 -2
View File
@@ -16,7 +16,7 @@ function* traverseGenerator(
node: FiberNode,
{
order = ["self", "child", "sibling"]
}: { order?: Array<"self"|"child"|"sibling"> } = {}
}: { order?: Array<"self" | "child" | "sibling"> } = {}
): IterableIterator<FiberNode> {
let skipChild = false,
skipSibling = false;
@@ -52,7 +52,9 @@ function* traverseGenerator(
};
// 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
for (const eachGen of orderedGenerators) {
+3 -1
View File
@@ -28,7 +28,9 @@ function isNodeComponentClass(
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) {
return true;
}
+1 -1
View File
@@ -17,7 +17,7 @@ describe("Component", () => {
it("should render correctly", () => {
const rootRef = React.createRef<C>();
rootRef.current && rootRef.current
rootRef.current && rootRef.current;
wrapper = mount(<C text="text" ref={rootRef} />, { attachTo: container });
expect(wrapper.html()).toMatchSnapshot();
+7 -2
View File
@@ -85,7 +85,7 @@ describe("findNodeByComponentName", () => {
const rootNode = mountAndGetRootNode(WrappedC, container);
const foundFnDepth1 = findNodeByComponentName(rootNode, FnDepth1.name);
const foundInner = findNodeByComponentName(foundFnDepth1, 'someName');
const foundInner = findNodeByComponentName(foundFnDepth1, "someName");
expect(foundInner).toBeFalsy();
expect(foundInner).toBe(null);
@@ -96,7 +96,12 @@ describe("findNodeByComponentName", () => {
return <Fn2 />;
}
function Fn2() {
return <div>Fn2 here<Fn3/></div>;
return (
<div>
Fn2 here
<Fn3 />
</div>
);
}
function Fn3() {
return <div>Fn3 here</div>;
+1 -1
View File
@@ -1,5 +1,5 @@
function FnDepth1() {
return null;
return null;
}
export default FnDepth1;
+1 -1
View File
@@ -13,7 +13,7 @@ import { mountAndGetRootNode } from "./utils/mountInEnzyme";
import CDepth1 from "./sample-components/depth-1-simple";
import CDepth2 from "./sample-components/depth-2-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", () => {
let container: HTMLDivElement;
+3 -3
View File
@@ -9,7 +9,7 @@ function createFunctionComponent(name?: string): React.FunctionComponent {
if (props.children !== undefined) {
return <React.Fragment>{props.children}</React.Fragment>;
} else {
return null
return null;
}
};
@@ -31,7 +31,7 @@ function createClassComponent(name?: string): React.ComponentClass {
if (this.props.children !== undefined) {
return this.props.children;
} else {
return null
return null;
}
}
};
@@ -113,7 +113,7 @@ function createClassComponents(
return returnArr;
}
// Handle other invalid inputs
throw new TypeError("Input is not valid");
}
+1 -1
View File
@@ -9,4 +9,4 @@ function getWrappedComponent(SomeComponent: React.ElementType) {
return WrappedC;
}
export default getWrappedComponent;
export default getWrappedComponent;
+1 -3
View File
@@ -1,9 +1,7 @@
import * as React from "react";
import { mount } from "enzyme";
import { FiberNode, FiberNodeForComponentClass } from "../../src/mocked-types";
import {
isConstructorFunctionComponent
} from "../../src/utils";
import { isConstructorFunctionComponent } from "../../src/utils";
import getWrappedComponent from "./getWrappedComponent";
export class RootNodeNotFoundError extends Error {