Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prettier 2.0; update project to use top-level lint and format #312

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.eslintignores don't seem to work if they are nested, unfortunately.

]
}
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 @@ -185,7 +177,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
36 changes: 9 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1941,16 +1941,6 @@
regexpp "^3.0.0"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@2.28.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.28.0.tgz#1fd0961cd8ef6522687b4c562647da6e71f8833d"
integrity sha512-4SL9OWjvFbHumM/Zh/ZeEjUFxrYKtdCi7At4GyKTbQlrj1HcphIDXlje4Uu4cY+qzszR5NdVin4CCm6AXCjd6w==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.28.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/experimental-utils@2.29.0", "@typescript-eslint/experimental-utils@^2.5.0":
version "2.29.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.29.0.tgz#3cb8060de9265ba131625a96bbfec31ba6d4a0fe"
Expand All @@ -1971,19 +1961,6 @@
"@typescript-eslint/typescript-estree" "2.29.0"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/typescript-estree@2.28.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.28.0.tgz#d34949099ff81092c36dc275b6a1ea580729ba00"
integrity sha512-HDr8MP9wfwkiuqzRVkuM3BeDrOC4cKbO5a6BymZBHUt5y/2pL0BXD6I/C/ceq2IZoHWhcASk+5/zo+dwgu9V8Q==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
glob "^7.1.6"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^6.3.0"
tsutils "^3.17.1"

"@typescript-eslint/typescript-estree@2.29.0":
version "2.29.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.29.0.tgz#1be6612bb02fc37ac9f466521c1459a4744e8d3a"
Expand Down Expand Up @@ -3859,6 +3836,11 @@ eslint-plugin-notice@^0.8.9:
lodash "^4.17.15"
metric-lcs "^0.1.2"

eslint-plugin-react-hooks@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-3.0.0.tgz#9e80c71846eb68dd29c3b21d832728aa66e5bd35"
integrity sha512-EjxTHxjLKIBWFgDJdhKKzLh5q+vjTFrqNZX36uIxWS4OfyXe5DawqPj3U5qeJ1ngLwatjzQnmR0Lz0J0YH3kxw==

eslint-plugin-react@^7.12.4, eslint-plugin-react@^7.16.0:
version "7.19.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.19.0.tgz#6d08f9673628aa69c5559d33489e855d83551666"
Expand Down Expand Up @@ -8352,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