Skip to content

Commit

Permalink
feat: prettier 2.0; update project to use top-level lint and format (#…
Browse files Browse the repository at this point in the history
…312)

- updating the project to use prettier 2.0

BREAKING CHANGE: prettier 2.0 may introduce breaking changes
  • Loading branch information
Paul Marbach committed Apr 28, 2020
1 parent 27a6be3 commit af8d93e
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 58 deletions.
1 change: 1 addition & 0 deletions .eslintignore
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": ["@spotify", "@spotify/eslint-config-oss"]
"extends": ["@spotify", "@spotify/eslint-config-oss"],
"ignorePatterns": [
"__fixtures__",
"packages/create-web-scripts-library/template"
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"postinstall": "./postinstall.sh",
"test": "lerna run test --stream",
"build": "lerna run build --stream",
"lint": "lerna run lint --stream",
"lint": "web-scripts lint --stylecheck",
"format": "web-scripts format",
"commit": "web-scripts commit",
"bootstrap": "lerna bootstrap --use-workspaces",
"release": "./release.sh"
Expand All @@ -22,7 +23,6 @@
"@spotify/eslint-config-oss": "^1.0.0",
"husky": "^4.0.0",
"lerna": "^3.20.2",
"prettier": "^1.18.2",
"typescript": "^3.7.4"
},
"husky": {
Expand Down
8 changes: 2 additions & 6 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
"type": "git",
"url": "git+https://github.com/spotify/web-scripts.git"
},
"scripts": {
"lint": "web-scripts lint"
},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0"
},
"scripts": {},
"devDependencies": {},
"peerDependencies": {
"eslint": ">=5.x"
},
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-config-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
"url": "git+https://github.com/spotify/web-scripts.git"
},
"main": "index.js",
"scripts": {
"lint": "web-scripts lint"
},
"scripts": {},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0",
"eslint": "^6.8.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.16.0",
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-config-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
"url": "git+https://github.com/spotify/web-scripts.git"
},
"main": "index.js",
"scripts": {
"lint": "web-scripts lint"
},
"scripts": {},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0",
"@typescript-eslint/eslint-plugin": "^2.14.0",
"@typescript-eslint/parser": "^2.14.0",
"eslint": "^6.8.0"
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"bugs": {
"url": "https://github.com/spotify/web-scripts/issues"
},
"scripts": {
"lint": "web-scripts lint"
},
"scripts": {},
"dependencies": {
"@spotify/eslint-config-base": "^6.2.0",
"@spotify/eslint-config-react": "^6.2.0",
Expand All @@ -33,7 +31,6 @@
"eslint-plugin-react-hooks": "^3.0.0"
},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0",
"eslint": "^6.8.0"
},
"peerDependencies": {
Expand Down
9 changes: 3 additions & 6 deletions packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
"url": "git+https://github.com/spotify/web-scripts.git"
},
"main": "index.js",
"scripts": {
"lint": "web-scripts lint"
},
"scripts": {},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0",
"prettier": "^1.18.2"
"prettier": "^2.0.5"
},
"peerDependencies": {
"prettier": "1.x"
"prettier": "2.x"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 1 addition & 3 deletions packages/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
"tsconfig.json"
],
"scripts": {
"test": "./run-tests.sh",
"lint": "web-scripts lint"
"test": "./run-tests.sh"
},
"devDependencies": {
"@spotify/web-scripts": "^6.2.0",
"typescript": "^3.7.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts-utils/src/has-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const hasConfig = (
cwd: getConsumingRoot(),
}) || { packageJson: {}, path: getConsumingRoot() };
const root = pkgPath.slice(0, pkgPath.length - '/package.json'.length);
return sources.some(source => {
return sources.some((source) => {
switch (source.type) {
case 'file':
return !!glob.sync(source.pattern, { cwd: root }).length;
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts-utils/src/has-key-in-obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const hasKeyInObj = (
): boolean => {
const [k, ...restOfK] = key.split('.');
if (restOfK.length === 0) {
return Object.keys(obj).some(ok => ok === k);
return Object.keys(obj).some((ok) => ok === k);
}
const nextObj = obj[k];
if (!(nextObj instanceof Object)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__fixtures__
__fixtures__
2 changes: 1 addition & 1 deletion packages/web-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"jest-config": "^25.1.0",
"jest-junit": "^10.0.0",
"lint-staged": "^10.0.4",
"prettier": "^1.18.2",
"prettier": "^2.0.5",
"semantic-release": "^17.0.1",
"ts-jest": "~25.2.1",
"typescript": "^3.7.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/Tasks/AuditTasks/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { join } from 'path';
import { auditTask } from '.';

// @ts-ignore
jest.spyOn(process, 'exit').mockImplementation(c => c);
jest.spyOn(process, 'exit').mockImplementation((c) => c);

jest.mock('cross-spawn-promise', () => jest.fn());

Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/Tasks/AuditTasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function auditTask(task: AuditTaskDesc): Promise<string[]> {
const fns = [yarnRun];

return await Promise.all(
fns.map(async fn => {
fns.map(async (fn) => {
dbg('Beginning %s task', fn.name);
const stdout = await fn(task);
dbg('Finished %s task', fn.name);
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/Tasks/BuildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function buildTask(task: BuildTaskDesc): Promise<string[]> {
}

return Promise.all(
fns.map(async fn => {
fns.map(async (fn) => {
dbg('Beginning %s task', fn.name);
const result = await fn(task);
dbg('Finished %s task', fn.name);
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/Tasks/CommitTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function precommitTask(
}

const results = await Promise.all(
fns.map(async fn => {
fns.map(async (fn) => {
dbg('Beginning %s task', fn.name);
const stdout = await fn(task);
dbg('Finished %s task', fn.name);
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/Tasks/FormatTask/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const readFile = promisify(readFileFS);
const mkdir = promisify(mkdirFS);

// @ts-ignore
jest.spyOn(process, 'exit').mockImplementation(c => c);
jest.spyOn(process, 'exit').mockImplementation((c) => c);

describe('web-scripts format', () => {
let pkgRoot: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/web-scripts/src/Tasks/FormatTask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export function getPrettierConfig(): string | null {
export function formatTask(task: FormatTaskDesc): SpawnSyncReturns<Buffer> {
const cmd = 'npx';
const config = task.config || getPrettierConfig();
const path = task.path || `${CONSUMING_ROOT}/src`;
const path = task.path || `${CONSUMING_ROOT}/**/src`;

const args = [
'--no-install',
'prettier',
...(config ? ['--config', config] : []),
'--write',
`${path}/**/*.[jt]s?(x)`,
`${path}/**/*.{ts,tsx,js,jsx}`,
];
dbg('npx args %o', args);
return spawn.sync(cmd, args, { stdio: 'inherit' });
Expand Down
4 changes: 2 additions & 2 deletions packages/web-scripts/src/Tasks/LintTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function lintTask(task: LintTaskDesc): Promise<string[]> {
if (task.stylecheck) fns.push(styleCheck);

return await Promise.all(
fns.map(async fn => {
fns.map(async (fn) => {
dbg('Beginning %s task', fn.name);
const stdout = await fn(task);
dbg('Finished %s task', fn.name);
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function styleCheck(): Promise<string> {
args.push('--config', config);
}

args.push('--check', `${CONSUMING_ROOT}/src/**/*.[jt]s?(x)`);
args.push('--check', `${CONSUMING_ROOT}/**/src/**/*.{ts,tsx,js,jsx}`);
const stdout = await spawn(cmd, args, { stdio: 'inherit' });
return (stdout || '').toString();
}
14 changes: 3 additions & 11 deletions packages/web-scripts/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,8 @@ const copyFile = promisify(copyFileFS);
// log output after the command finishes
const exec = async (cmd: string, options?: object) => {
function _log(resp: { stdout?: string | Buffer; stderr?: string | Buffer }) {
if (resp.stdout)
resp.stdout
.toString()
.split('\n')
.forEach(dbg);
if (resp.stderr)
resp.stderr
.toString()
.split('\n')
.forEach(dbg);
if (resp.stdout) resp.stdout.toString().split('\n').forEach(dbg);
if (resp.stderr) resp.stderr.toString().split('\n').forEach(dbg);
}
try {
const resp = await execPromise(cmd, options);
Expand Down Expand Up @@ -188,7 +180,7 @@ describe('integration tests', () => {
);

await mkdir(join(PKG_ROOT, 'src'));
await fileNames.map(fileName =>
await fileNames.map((fileName) =>
copyFile(
join(THIS_ROOT, '__fixtures__', fileName),
join(PKG_ROOT, 'src', fileName),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8334,10 +8334,10 @@ prepend-http@^1.0.1:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=

prettier@^1.18.2:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
prettier@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

pretty-format@^24.9.0:
version "24.9.0"
Expand Down

0 comments on commit af8d93e

Please sign in to comment.