From baa2e6d728672b59e31ffc564a89c7be960aa7e9 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 7 Jun 2022 17:12:49 -0700 Subject: [PATCH] Unify Prettier config and enforce Prettier in GitHub CI (#3953) Summary: This PR starts with an intentional error to confirm that it reports errors in CI. Pull Request resolved: https://github.com/facebook/relay/pull/3953 Test Plan: Imported from GitHub, without a `Test Plan:` line. **Static Docs Preview: relay** |[Full Site](https://our.intern.facebook.com/intern/staticdocs/eph/D36989721/V2/relay/)| |**Modified Pages**| Reviewed By: josephsavona Differential Revision: D36989721 Pulled By: captbaritone fbshipit-source-id: 87acb3726eba88fb8a438ccae8f6d0f5553e522c --- .github/workflows/ci.yml | 2 ++ flow-typed/react.js | 2 +- gulpfile.js | 22 +++++++++---------- package.json | 6 +++-- scripts/testDependencies.js | 6 ++--- vscode-extension/package.json | 7 ++++-- website/docusaurus.config.js | 3 +-- website/package.json | 9 ++++++++ website/src/compiler-explorer/Editor.js | 2 +- .../src/compiler-explorer/ExplorerState.js | 8 +++---- .../ExplorerStateConstants.js | 4 +--- website/src/core/Container.js | 2 +- website/src/core/DocsRating/index.js | 2 +- website/src/pages/compiler-explorer.js | 6 ++--- website/src/pages/help.js | 2 +- website/src/pages/index.js | 4 ++-- website/src/pages/users.js | 4 ++-- website/src/pages/versions.js | 6 ++--- 18 files changed, 55 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4fc107cdb07e..55d882b4222c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,8 @@ jobs: run: yarn run test-dependencies - name: Lint run: yarn run lint + - name: Prettier + run: yarn run prettier-check typecheck: name: Flow Typecheck diff --git a/flow-typed/react.js b/flow-typed/react.js index 891359111a886..f0dc2115be319 100644 --- a/flow-typed/react.js +++ b/flow-typed/react.js @@ -122,7 +122,7 @@ declare module react { declare export function useState( initialState: (() => S) | S, - ): [S, (((S) => S) | S) => void]; + ): [S, ((S => S) | S) => void]; declare type Dispatch = (A) => void; diff --git a/gulpfile.js b/gulpfile.js index 1988463e8de43..57e7ed6186842 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -215,7 +215,7 @@ const builds = [ const modules = gulp.parallel( ...builds.map( - (build) => + build => function modulesTask() { return gulp .src(INCLUDE_GLOBS, { @@ -229,7 +229,7 @@ const modules = gulp.parallel( const flowDefs = gulp.parallel( ...builds.map( - (build) => + build => function modulesTask() { return gulp .src(['**/*.js', '!**/__tests__/**/*.js', '!**/__mocks__/**/*.js'], { @@ -242,7 +242,7 @@ const flowDefs = gulp.parallel( ); const copyFilesTasks = []; -builds.forEach((build) => { +builds.forEach(build => { copyFilesTasks.push( function copyLicense() { return gulp @@ -280,9 +280,9 @@ const exportsFiles = gulp.series( modules, gulp.parallel( ...builds.map( - (build) => + build => function exportsFilesTask(done) { - Object.keys(build.exports).map((exportName) => + Object.keys(build.exports).map(exportName => fs.writeFileSync( path.join(DIST, build.package, exportName + '.js'), PRODUCTION_HEADER + @@ -296,8 +296,8 @@ const exportsFiles = gulp.series( ); const bundlesTasks = []; -builds.forEach((build) => { - build.bundles.forEach((bundle) => { +builds.forEach(build => { + build.bundles.forEach(bundle => { bundlesTasks.push(function bundleTask() { return gulp .src(path.join(DIST, build.package, 'lib', bundle.entry)) @@ -312,8 +312,8 @@ builds.forEach((build) => { const bundles = gulp.series(bundlesTasks); const bundlesMinTasks = []; -builds.forEach((build) => { - build.bundles.forEach((bundle) => { +builds.forEach(build => { + build.bundles.forEach(bundle => { bundlesMinTasks.push(function bundlesMinTask() { return gulp .src(path.join(DIST, build.package, 'lib', bundle.entry)) @@ -377,9 +377,9 @@ const setMainVersion = async () => { if (!RELEASE_COMMIT_SHA) { throw new Error('Expected the RELEASE_COMMIT_SHA env variable to be set.'); } - const packages = builds.map((build) => build.package); + const packages = builds.map(build => build.package); packages.push('relay-compiler'); - packages.forEach((pkg) => { + packages.forEach(pkg => { const pkgJsonPath = path.join('.', 'dist', pkg, 'package.json'); const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')); packageJson.version = VERSION; diff --git a/package.json b/package.json index 2f4c2d59b0201..dd7676de76d50 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "postinstall": "npm run build", "prepublishOnly": "npm run build:clean", "prettier": "find . -name node_modules -prune -or -name dist -prune -or -name '*.js' -print | xargs prettier --write", + "prettier-check": "find . -name node_modules -prune -or -name dist -prune -or -name '*.js' -print | xargs prettier --check", "test": "f() { EXIT=0; npm run typecheck || EXIT=$?; npm run test-dependencies || EXIT=$?; npm run jest \"$@\" || EXIT=$?; exit $EXIT; }; f", "test-dependencies": "node ./scripts/testDependencies.js", "typecheck": "flow check" @@ -76,12 +77,13 @@ "npm": ">=2.x" }, "prettier": { + "arrowParens": "avoid", "bracketSameLine": true, "bracketSpacing": false, - "parser": "flow", "requirePragma": true, "singleQuote": true, - "trailingComma": "all" + "trailingComma": "all", + "parser": "flow" }, "jest": { "testRegex": "/__tests__/.*-test\\.js$", diff --git a/scripts/testDependencies.js b/scripts/testDependencies.js index 1510f27904f60..b7ea59dbe2ab3 100644 --- a/scripts/testDependencies.js +++ b/scripts/testDependencies.js @@ -20,12 +20,12 @@ if (module.parent) { const packagesRoot = path.join(topLevelPackagePath, 'packages'); const packagePaths = fs .readdirSync(packagesRoot) - .map((filepath) => path.join(packagesRoot, filepath)) - .filter((filepath) => fs.statSync(filepath).isDirectory()); + .map(filepath => path.join(packagesRoot, filepath)) + .filter(filepath => fs.statSync(filepath).isDirectory()); const errors = testDependencies(topLevelPackagePath, packagePaths); if (errors.length !== 0) { - errors.forEach((error) => console.error(error)); + errors.forEach(error => console.error(error)); process.exit(1); } } diff --git a/vscode-extension/package.json b/vscode-extension/package.json index dd1a2dfac74ff..2a0652bfeebbe 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -134,10 +134,13 @@ } }, "prettier": { + "arrowParens": "avoid", "bracketSameLine": true, - "bracketSpacing": true, + "bracketSpacing": false, + "requirePragma": true, "singleQuote": true, - "trailingComma": "all" + "trailingComma": "all", + "parser": "flow" }, "scripts": { "typecheck": "tsc --noEmit", diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 668a5d2ce782d..d1c0121cdd157 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -224,8 +224,7 @@ module.exports = { external: [ 'current', ...versions.filter( - (version) => - version !== 'experimental' && version !== 'classic', + version => version !== 'experimental' && version !== 'classic', ), ], }), diff --git a/website/package.json b/website/package.json index f11a5d0bd4c97..1df5014ed0e3b 100644 --- a/website/package.json +++ b/website/package.json @@ -40,5 +40,14 @@ "highlight.js": "^10.4.1", "shelljs": "^0.8.5", "ansi-html": "0.0.8" + }, + "prettier": { + "arrowParens": "avoid", + "bracketSameLine": true, + "bracketSpacing": false, + "requirePragma": true, + "singleQuote": true, + "trailingComma": "all", + "parser": "flow" } } diff --git a/website/src/compiler-explorer/Editor.js b/website/src/compiler-explorer/Editor.js index f559c9691a75c..4d7eee84c8324 100644 --- a/website/src/compiler-explorer/Editor.js +++ b/website/src/compiler-explorer/Editor.js @@ -69,7 +69,7 @@ export default function Editor({text, onDidChange, diagnostics, style}) { return; } - const markers = (diagnostics ?? []).map((diagnostic) => { + const markers = (diagnostics ?? []).map(diagnostic => { return { severity: 8, // Error message: diagnostic.message, diff --git a/website/src/compiler-explorer/ExplorerState.js b/website/src/compiler-explorer/ExplorerState.js index eebc3336a0511..9858c1723d427 100644 --- a/website/src/compiler-explorer/ExplorerState.js +++ b/website/src/compiler-explorer/ExplorerState.js @@ -30,14 +30,14 @@ export function useExplorerState() { const actionHandlers = useMemo(() => { return { - setSchemaText: (schemaText) => + setSchemaText: schemaText => dispatch({type: 'UPDATE_SCHEMA', schemaText}), - setDocumentText: (documentText) => + setDocumentText: documentText => dispatch({type: 'UPDATE_DOCUMENT', documentText}), setFeatureFlag: (flag, value) => dispatch({type: 'SET_FEATURE_FLAG', flag, value}), - setLanguage: (language) => dispatch({type: 'SET_LANGUAGE', language}), - setOutputType: (outputType) => + setLanguage: language => dispatch({type: 'SET_LANGUAGE', language}), + setOutputType: outputType => dispatch({type: 'SET_OUTPUT_TYPE', outputType}), }; }, []); diff --git a/website/src/compiler-explorer/ExplorerStateConstants.js b/website/src/compiler-explorer/ExplorerStateConstants.js index 63000a3664972..6db1bb8308146 100644 --- a/website/src/compiler-explorer/ExplorerStateConstants.js +++ b/website/src/compiler-explorer/ExplorerStateConstants.js @@ -79,8 +79,6 @@ export const DEFAULT_STATE = { schemaText: DEFAULT_SCHEMA, documentText: DEFAULT_DOCUMENT, outputType: 'operation', - featureFlags: Object.fromEntries( - FEATURE_FLAGS.map((f) => [f.key, f.default]), - ), + featureFlags: Object.fromEntries(FEATURE_FLAGS.map(f => [f.key, f.default])), language: 'typescript', }; diff --git a/website/src/core/Container.js b/website/src/core/Container.js index 961ebad954804..d58570d888e59 100644 --- a/website/src/core/Container.js +++ b/website/src/core/Container.js @@ -12,7 +12,7 @@ import classNames from 'classnames'; import * as React from 'react'; /* eslint-enable lint/no-value-import */ -const Container = (props) => { +const Container = props => { const containerClasses = classNames('container', props.className, { darkBackground: props.background === 'dark', highlightBackground: props.background === 'highlight', diff --git a/website/src/core/DocsRating/index.js b/website/src/core/DocsRating/index.js index 3d9b1c0fd6148..d291deadebf3e 100644 --- a/website/src/core/DocsRating/index.js +++ b/website/src/core/DocsRating/index.js @@ -51,7 +51,7 @@ function Wrapper({children}) { const FeedbackButtons = () => { const [hasProvidedFeedback, setHasProvidedFeedback] = React.useState(false); - const provideFeedback = (value) => { + const provideFeedback = value => { setHasProvidedFeedback(true); provideFeedbackToGoogleAnalytics(value); }; diff --git a/website/src/pages/compiler-explorer.js b/website/src/pages/compiler-explorer.js index 4ddcd0469f914..e4ce54b6a76f6 100644 --- a/website/src/pages/compiler-explorer.js +++ b/website/src/pages/compiler-explorer.js @@ -97,7 +97,7 @@ function CompilerExplorer() { {value: 'types', label: 'Types'}, ]} selectedValue={state.outputType} - setSelectedValue={(selected) => setOutputType(selected)} + setSelectedValue={selected => setOutputType(selected)} /> @@ -148,7 +148,7 @@ function Config({featureFlags, setFeatureFlag}) { setFeatureFlag(key, e.target.checked)} + onChange={e => setFeatureFlag(key, e.target.checked)} /> {label} @@ -163,7 +163,7 @@ function TypegenConfig({setLanguage, language}) {
@@ -43,7 +43,7 @@ const Users = () => { ); }; -export default (props) => ( +export default props => ( diff --git a/website/src/pages/versions.js b/website/src/pages/versions.js index 99788ec84281f..633e01ac44e86 100644 --- a/website/src/pages/versions.js +++ b/website/src/pages/versions.js @@ -19,9 +19,9 @@ function Version() { const {siteConfig} = useDocusaurusContext(); const versions = useVersions(); const latestVersion = useLatestVersion(); - const currentVersion = versions.find((version) => version.name === 'current'); + const currentVersion = versions.find(version => version.name === 'current'); const pastVersions = versions.filter( - (version) => + version => version !== latestVersion.name && version !== currentVersion.name, ); const repoUrl = `https://github.com/${siteConfig.organizationName}/${siteConfig.projectName}`; @@ -85,7 +85,7 @@ function Version() {

- {pastVersions.map((version) => ( + {pastVersions.map(version => (
{version.label}