From 8c6f7b560e9917cd69d081ddb24af6c3d86c9694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Mon, 27 Apr 2020 21:24:12 +0200 Subject: [PATCH] style: prettier format --- README.md | 2 +- api/svgr.js | 4 +-- .../src/index.js | 4 +-- .../src/index.js | 2 +- .../src/index.js | 6 ++--- .../src/index.js | 6 ++--- .../src/index.js | 4 +-- .../src/index.test.js | 4 +-- packages/babel-preset/src/index.js | 4 +-- packages/cli/src/index.test.js | 13 ++++------ packages/core/README.md | 10 +++++--- packages/core/src/config.js | 2 +- packages/core/src/config.test.js | 16 ++++++------ packages/core/src/convert.test.js | 2 +- packages/hast-util-to-babel-ast/README.md | 2 +- packages/hast-util-to-babel-ast/src/all.js | 2 +- .../src/getAttributes.js | 2 +- packages/hast-util-to-babel-ast/src/util.js | 2 +- packages/parcel-plugin-svgr/src/index.test.js | 6 ++--- packages/plugin-svgo/src/index.js | 4 +-- packages/rollup/src/index.test.js | 2 +- packages/webpack/src/index.js | 8 +++--- website/src/components/playground/Loading.js | 4 +-- .../src/components/playground/Playground.js | 25 ++++++++++++------- website/src/components/playground/Query.js | 4 +-- website/src/components/playground/Settings.js | 4 +-- .../playground/SettingsFieldEnum.js | 2 +- .../components/playground/SettingsGroup.js | 2 +- .../components/playground/config/settings.js | 6 ++--- .../playground/icons/ChevronLeft.js | 2 +- 30 files changed, 82 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 1d207587..2aed4045 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ npx @svgr/cli --icon --replace-attr-values "#063855=currentColor" icon.svg ```js import * as React from 'react' -const SvgComponent = props => ( +const SvgComponent = (props) => ( diff --git a/api/svgr.js b/api/svgr.js index 05bacaf9..1088693a 100644 --- a/api/svgr.js +++ b/api/svgr.js @@ -11,10 +11,10 @@ module.exports = (req, res) => { return } svgr(req.body.code, { ...req.body.options, plugins: [svgo, jsx, prettier] }) - .then(output => { + .then((output) => { res.status(200).json({ output }) }) - .catch(error => { + .catch((error) => { res.status(400).json({ error: error.message }) }) } diff --git a/packages/babel-plugin-add-jsx-attribute/src/index.js b/packages/babel-plugin-add-jsx-attribute/src/index.js index 3b6101d2..c64e5a14 100644 --- a/packages/babel-plugin-add-jsx-attribute/src/index.js +++ b/packages/babel-plugin-add-jsx-attribute/src/index.js @@ -52,7 +52,7 @@ const addJSXAttribute = ({ types: t, template }, opts) => { const newAttribute = getAttribute({ spread, name, value, literal }) const attributes = path.get('attributes') - const isEqualAttribute = attribute => { + const isEqualAttribute = (attribute) => { if (spread) { return attribute.get('argument').isIdentifier({ name }) } @@ -60,7 +60,7 @@ const addJSXAttribute = ({ types: t, template }, opts) => { return attribute.get('name').isJSXIdentifier({ name }) } - const replaced = attributes.some(attribute => { + const replaced = attributes.some((attribute) => { if (!isEqualAttribute(attribute)) return false attribute.replaceWith(newAttribute) return true diff --git a/packages/babel-plugin-remove-jsx-attribute/src/index.js b/packages/babel-plugin-remove-jsx-attribute/src/index.js index 86bef1fc..182b4ad4 100644 --- a/packages/babel-plugin-remove-jsx-attribute/src/index.js +++ b/packages/babel-plugin-remove-jsx-attribute/src/index.js @@ -3,7 +3,7 @@ const removeJSXAttribute = (api, opts) => ({ JSXOpeningElement(path) { if (!opts.elements.includes(path.node.name.name)) return - path.get('attributes').forEach(attribute => { + path.get('attributes').forEach((attribute) => { const nodeName = attribute.node.name if (nodeName && opts.attributes.includes(nodeName.name)) { attribute.remove() diff --git a/packages/babel-plugin-svg-dynamic-title/src/index.js b/packages/babel-plugin-svg-dynamic-title/src/index.js index cc94e9ea..e68f39c4 100644 --- a/packages/babel-plugin-svg-dynamic-title/src/index.js +++ b/packages/babel-plugin-svg-dynamic-title/src/index.js @@ -4,7 +4,7 @@ const plugin = ({ types: t }) => ({ visitor: { JSXElement(path) { if ( - !elements.some(element => + !elements.some((element) => path.get('openingElement.name').isJSXIdentifier({ name: element }), ) ) { @@ -28,7 +28,7 @@ const plugin = ({ types: t }) => ({ function enhanceAttributes(attributes) { const existingId = attributes.find( - attribute => attribute.name.name === 'id', + (attribute) => attribute.name.name === 'id', ) if (!existingId) { return [...attributes, createTitleIdAttribute()] @@ -89,7 +89,7 @@ const plugin = ({ types: t }) => ({ // store the title element let titleElement - const hasTitle = path.get('children').some(childPath => { + const hasTitle = path.get('children').some((childPath) => { if (!childPath.isJSXElement()) return false if (childPath.node === titleElement) return false if (childPath.node.openingElement.name.name !== 'title') return false diff --git a/packages/babel-plugin-svg-em-dimensions/src/index.js b/packages/babel-plugin-svg-em-dimensions/src/index.js index e6c6c350..a0a53b07 100644 --- a/packages/babel-plugin-svg-em-dimensions/src/index.js +++ b/packages/babel-plugin-svg-em-dimensions/src/index.js @@ -5,7 +5,7 @@ const plugin = ({ types: t }) => ({ JSXOpeningElement: { enter(path) { if ( - !elements.some(element => + !elements.some((element) => path.get('name').isJSXIdentifier({ name: element }), ) ) @@ -14,7 +14,7 @@ const plugin = ({ types: t }) => ({ const requiredAttributes = ['width', 'height'] const attributeValue = '1em' - path.get('attributes').forEach(attributePath => { + path.get('attributes').forEach((attributePath) => { if (!attributePath.isJSXAttribute()) return const index = requiredAttributes.indexOf(attributePath.node.name.name) @@ -25,7 +25,7 @@ const plugin = ({ types: t }) => ({ requiredAttributes.splice(index, 1) }) - requiredAttributes.forEach(attribute => { + requiredAttributes.forEach((attribute) => { path.pushContainer( 'attributes', t.jsxAttribute( diff --git a/packages/babel-plugin-transform-react-native-svg/src/index.js b/packages/babel-plugin-transform-react-native-svg/src/index.js index 39806c0d..85f68b71 100644 --- a/packages/babel-plugin-transform-react-native-svg/src/index.js +++ b/packages/babel-plugin-transform-react-native-svg/src/index.js @@ -76,11 +76,11 @@ const plugin = ({ types: t }, { expo }) => { const importDeclarationVisitor = { ImportDeclaration(path, state) { if (path.get('source').isStringLiteral({ value: 'react-native-svg' })) { - state.replacedComponents.forEach(component => { + state.replacedComponents.forEach((component) => { if ( path .get('specifiers') - .some(specifier => + .some((specifier) => specifier.get('local').isIdentifier({ name: component }), ) ) { diff --git a/packages/babel-plugin-transform-svg-component/src/index.test.js b/packages/babel-plugin-transform-svg-component/src/index.test.js index d7c6ffeb..9b8868c9 100644 --- a/packages/babel-plugin-transform-svg-component/src/index.test.js +++ b/packages/babel-plugin-transform-svg-component/src/index.test.js @@ -1,7 +1,7 @@ import { transform } from '@babel/core' import plugin from '.' -const testPlugin = language => (code, options) => { +const testPlugin = (language) => (code, options) => { const result = transform(code, { plugins: [ '@babel/plugin-syntax-jsx', @@ -14,7 +14,7 @@ const testPlugin = language => (code, options) => { } describe('plugin', () => { - describe.each(['javascript', 'typescript'])('%s', language => { + describe.each(['javascript', 'typescript'])('%s', (language) => { it('transforms whole program', () => { const { code } = testPlugin(language)('', { state: { componentName: 'SvgComponent' }, diff --git a/packages/babel-preset/src/index.js b/packages/babel-preset/src/index.js index 2148c6ca..68e66f10 100644 --- a/packages/babel-preset/src/index.js +++ b/packages/babel-preset/src/index.js @@ -14,14 +14,14 @@ function getAttributeValue(value) { } function propsToAttributes(props) { - return Object.keys(props).map(name => { + return Object.keys(props).map((name) => { const { literal, value } = getAttributeValue(props[name]) return { name, literal, value } }) } function replaceMapToValues(replaceMap) { - return Object.keys(replaceMap).map(value => { + return Object.keys(replaceMap).map((value) => { const { literal, value: newValue } = getAttributeValue(replaceMap[value]) return { value, newValue, literal } }) diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js index 647e05a2..7d29753b 100644 --- a/packages/cli/src/index.test.js +++ b/packages/cli/src/index.test.js @@ -11,7 +11,7 @@ const svgr = path.join(__dirname, 'index.js') const babelNode = path.join(__dirname, '../../../node_modules/.bin/babel-node') describe('cli', () => { - const cli = async args => { + const cli = async (args) => { const { stdout } = await exec(`${babelNode} -- ${svgr} ${args}`) return stdout } @@ -60,7 +60,7 @@ describe('cli', () => { const sorted = result .split(/\n/) .sort() - .map(x => x.toLowerCase()) + .map((x) => x.toLowerCase()) .join('\n') expect(sorted).toMatchSnapshot() }, 10000) @@ -72,7 +72,7 @@ describe('cli', () => { const sorted = result .split(/\n/) .sort() - .map(x => x.toLowerCase()) + .map((x) => x.toLowerCase()) .join('\n') expect(sorted).toMatchSnapshot() }, 10000) @@ -81,10 +81,7 @@ describe('cli', () => { const result = await cli( '--silent --out-dir __fixtures_build__/whole __fixtures__', ) - const sorted = result - .split(/\n/) - .sort() - .join('\n') + const sorted = result.split(/\n/).sort().join('\n') expect(sorted).toMatchSnapshot() }, 10000) @@ -136,7 +133,7 @@ describe('cli', () => { ['--typescript --ref --title-prop'], ])( 'should support various args', - async args => { + async (args) => { const result = await cli(`${args} __fixtures__/simple/file.svg`) expect(result).toMatchSnapshot(args) }, diff --git a/packages/core/README.md b/packages/core/README.md index 1ee5f6c2..efb31756 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -23,9 +23,11 @@ const svgCode = ` ` -svgr(svgCode, { icon: true }, { componentName: 'MyComponent' }).then(jsCode => { - console.log(jsCode) -}) +svgr(svgCode, { icon: true }, { componentName: 'MyComponent' }).then( + (jsCode) => { + console.log(jsCode) + }, +) ``` Use `svgr.sync(code, config, state)` if you would like to use sync version. @@ -37,7 +39,7 @@ By default `@svgr/core` doesn't include `svgo` and `prettier` plugins, if you wa ```js svgr(svgCode, { plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'], -}).then(jsCode => { +}).then((jsCode) => { console.log(jsCode) }) ``` diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 6c9db468..a492e9a5 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -55,7 +55,7 @@ export async function resolveConfigFile(filePath) { return result ? result.filepath : null } -resolveConfigFile.sync = filePath => { +resolveConfigFile.sync = (filePath) => { const result = explorerSync.search(filePath) return result ? result.filepath : null } diff --git a/packages/core/src/config.test.js b/packages/core/src/config.test.js index 11379a0d..01c03c94 100644 --- a/packages/core/src/config.test.js +++ b/packages/core/src/config.test.js @@ -4,7 +4,7 @@ import { resolveConfig, resolveConfigFile, loadConfig } from './config' const getMethod = (method, mode) => (mode === 'sync' ? method.sync : method) describe('svgo', () => { - describe.each([['sync'], ['async']])('%s', mode => { + describe.each([['sync'], ['async']])('%s', (mode) => { describe(`#resolveConfig [${mode}]`, () => { it('should return null if no config found', async () => { const config = await getMethod(resolveConfig, mode)('/tmp') @@ -12,9 +12,10 @@ describe('svgo', () => { }) it('should return config if found', async () => { - const config = await getMethod(resolveConfig, mode)( - path.join(__dirname, '__fixtures__/svgr'), - ) + const config = await getMethod( + resolveConfig, + mode, + )(path.join(__dirname, '__fixtures__/svgr')) expect(config).toEqual({ icon: true, noSemi: true, @@ -30,9 +31,10 @@ describe('svgo', () => { }) it('should return config path if found', async () => { - const config = await getMethod(resolveConfigFile, mode)( - path.join(__dirname, '__fixtures__/svgr'), - ) + const config = await getMethod( + resolveConfigFile, + mode, + )(path.join(__dirname, '__fixtures__/svgr')) expect(config).toMatch(/__fixtures__(\/|\\)svgr(\/|\\)\.svgrrc$/) }) }) diff --git a/packages/core/src/convert.test.js b/packages/core/src/convert.test.js index e1b8c092..bad043ef 100644 --- a/packages/core/src/convert.test.js +++ b/packages/core/src/convert.test.js @@ -311,7 +311,7 @@ describe('convert', () => { { memo: true }, ] - test.each(configs)('should support options %#', async config => { + test.each(configs)('should support options %#', async (config) => { const result = await convertWithAllPlugins(svgBaseCode, config) expect(result).toMatchSnapshot() }) diff --git a/packages/hast-util-to-babel-ast/README.md b/packages/hast-util-to-babel-ast/README.md index f2df68d3..f4d3e93c 100644 --- a/packages/hast-util-to-babel-ast/README.md +++ b/packages/hast-util-to-babel-ast/README.md @@ -15,7 +15,7 @@ npm install --save-dev @svgr/hast-util-to-babel-ast ## Usage ```js -import { parse } from 'svg-parser'; +import { parse } from 'svg-parser' import toBabelAST from '@svgr/hast-util-to-babel-ast' const hastTree = parse(``) diff --git a/packages/hast-util-to-babel-ast/src/all.js b/packages/hast-util-to-babel-ast/src/all.js index 255f12e4..18dcc053 100644 --- a/packages/hast-util-to-babel-ast/src/all.js +++ b/packages/hast-util-to-babel-ast/src/all.js @@ -12,7 +12,7 @@ function all(h, parent) { values.push(result) } - return values.filter(node => node) + return values.filter((node) => node) } export default all diff --git a/packages/hast-util-to-babel-ast/src/getAttributes.js b/packages/hast-util-to-babel-ast/src/getAttributes.js index fbc0c89b..6270caf9 100644 --- a/packages/hast-util-to-babel-ast/src/getAttributes.js +++ b/packages/hast-util-to-babel-ast/src/getAttributes.js @@ -49,7 +49,7 @@ function getValue(key, value) { return t.stringLiteral(replaceSpaces(value)) } -const getAttributes = node => { +const getAttributes = (node) => { const keys = Object.keys(node.properties) const attributes = [] let index = -1 diff --git a/packages/hast-util-to-babel-ast/src/util.js b/packages/hast-util-to-babel-ast/src/util.js index 5ab94576..191d1cef 100644 --- a/packages/hast-util-to-babel-ast/src/util.js +++ b/packages/hast-util-to-babel-ast/src/util.js @@ -35,7 +35,7 @@ export function trimEnd(haystack, needle) { const KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g export function kebabCase(str) { - return str.replace(KEBAB_REGEX, match => `-${match.toLowerCase()}`) + return str.replace(KEBAB_REGEX, (match) => `-${match.toLowerCase()}`) } const SPACES_REGEXP = /[\t\r\n\u0085\u2028\u2029]+/g diff --git a/packages/parcel-plugin-svgr/src/index.test.js b/packages/parcel-plugin-svgr/src/index.test.js index 33b11354..0a9cc495 100644 --- a/packages/parcel-plugin-svgr/src/index.test.js +++ b/packages/parcel-plugin-svgr/src/index.test.js @@ -2,10 +2,10 @@ import Bundler from 'parcel' import path from 'path' import plugin from '.' -const getCode = bundle => +const getCode = (bundle) => Array.from(bundle.assets) - .filter(asset => asset.id === 'icon.svg') - .map(asset => asset.generated) + .filter((asset) => asset.id === 'icon.svg') + .map((asset) => asset.generated) describe('parcel plugin', () => { it('should convert file', async () => { diff --git a/packages/plugin-svgo/src/index.js b/packages/plugin-svgo/src/index.js index 4fb9908e..d8c0c2ab 100644 --- a/packages/plugin-svgo/src/index.js +++ b/packages/plugin-svgo/src/index.js @@ -13,7 +13,7 @@ const explorer = cosmiconfigSync('svgo', { 'svgo.config.js', '.svgo.yml', ], - transform: result => result && result.config, + transform: (result) => result && result.config, cache: true, }) @@ -58,7 +58,7 @@ function optimizeSync(svgstr, info) { let result - const optimizeOnceCallback = svgjs => { + const optimizeOnceCallback = (svgjs) => { if (svgjs.error) { throw svgjs.error } diff --git a/packages/rollup/src/index.test.js b/packages/rollup/src/index.test.js index 43a54e25..56ece938 100644 --- a/packages/rollup/src/index.test.js +++ b/packages/rollup/src/index.test.js @@ -9,7 +9,7 @@ const compile = (plugins = [svgr()]) => plugins, }) -const getCode = bundler => +const getCode = (bundler) => bundler.cache.modules.find( ({ id }) => id.includes('__fixtures__/simple/file.svg') || diff --git a/packages/webpack/src/index.js b/packages/webpack/src/index.js index 5baa670c..20fb67ea 100644 --- a/packages/webpack/src/index.js +++ b/packages/webpack/src/index.js @@ -40,7 +40,7 @@ function svgrLoader(source) { return exportMatches ? `export default ${exportMatches[1]}` : null })() - const tranformSvg = svg => + const tranformSvg = (svg) => convert(svg, options, { caller: { name: '@svgr/webpack', @@ -49,12 +49,12 @@ function svgrLoader(source) { }, filePath: this.resourcePath, }) - .then(jsCode => { + .then((jsCode) => { if (!babel) return jsCode return transformAsync(jsCode, babelOptions).then(({ code }) => code) }) - .then(result => callback(null, result)) - .catch(err => callback(err)) + .then((result) => callback(null, result)) + .catch((err) => callback(err)) if (previousExport) { readSvg().then(tranformSvg) diff --git a/website/src/components/playground/Loading.js b/website/src/components/playground/Loading.js index b7cb3d9d..b4b410e4 100644 --- a/website/src/components/playground/Loading.js +++ b/website/src/components/playground/Loading.js @@ -22,7 +22,7 @@ const fadeIn = keyframes` const Loader = styled.div` flex: 1; animation: ${fadeIn} 1000ms ease-in infinite alternate; - background: url(${p => p.backgroundImage}) center no-repeat; + background: url(${(p) => p.backgroundImage}) center no-repeat; background-size: 30%; ` @@ -30,7 +30,7 @@ export function Loading() { return ( ( + render={(data) => ( )} /> diff --git a/website/src/components/playground/Playground.js b/website/src/components/playground/Playground.js index 26b2f406..96323e23 100644 --- a/website/src/components/playground/Playground.js +++ b/website/src/components/playground/Playground.js @@ -322,15 +322,22 @@ export function Playground() { { - // Detect copy - if ((event.metaKey || event.ctrlKey) && event.key === 'c') { - setTimeout(() => { - dialog.show() - setDialogDisplayed(true) - }, 50) - } - }} + onKeyDown={ + dialogDisplayed + ? null + : (event) => { + // Detect copy + if ( + (event.metaKey || event.ctrlKey) && + event.key === 'c' + ) { + setTimeout(() => { + dialog.show() + setDialogDisplayed(true) + }, 50) + } + } + } > diff --git a/website/src/components/playground/Query.js b/website/src/components/playground/Query.js index c02d3445..ebe3334f 100644 --- a/website/src/components/playground/Query.js +++ b/website/src/components/playground/Query.js @@ -39,7 +39,7 @@ function useLocation() { const history = useHistory() const [location, setLocation] = React.useState(getLocation) React.useEffect(() => { - return history.listen(location => setLocation(location)) + return history.listen((location) => setLocation(location)) }, []) return location } @@ -53,7 +53,7 @@ export function useQuery(getInitialState = {}) { locationRef.current = location }) const setState = React.useCallback( - state => { + (state) => { const search = formatQuery({ ...initialState, ...state }, initialState) if (locationRef.current.search !== search) { history.push({ diff --git a/website/src/components/playground/Settings.js b/website/src/components/playground/Settings.js index 4f745d37..7e20391c 100644 --- a/website/src/components/playground/Settings.js +++ b/website/src/components/playground/Settings.js @@ -27,7 +27,7 @@ const SettingsContainer = styled.div` ` const getGroupSettings = (group, settings) => - settings.filter(setting => setting.group === group) + settings.filter((setting) => setting.group === group) const settingComponents = { boolean: SettingsFieldBoolean, @@ -36,7 +36,7 @@ const settingComponents = { integer: SettingsFieldInteger, } -const renderSetting = setting => { +const renderSetting = (setting) => { const SettingComponent = settingComponents[setting.type] if (!SettingComponent) throw new Error(`Unknown setting type ${setting.type}`) return diff --git a/website/src/components/playground/SettingsFieldEnum.js b/website/src/components/playground/SettingsFieldEnum.js index 34b3ff0d..6fa7a259 100644 --- a/website/src/components/playground/SettingsFieldEnum.js +++ b/website/src/components/playground/SettingsFieldEnum.js @@ -9,7 +9,7 @@ export function SettingsFieldEnum({ setting }) { {setting.label} - {setting.values.map(value => ( + {setting.values.map((value) => ( - {hiddenDisclosureProps => ( + {(hiddenDisclosureProps) => (