Skip to content

Commit 0822ae2

Browse files
author
Paul Marbach
committed
feat(web-scripts): add checkstyle to lint
1 parent b544c65 commit 0822ae2

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"test": "lerna run test --stream",
1111
"build": "lerna run build --stream",
12-
"lint": "web-scripts lint --ignore-path .gitignore",
12+
"lint": "lerna run lint --stream",
1313
"commit": "web-scripts commit",
1414
"bootstrap": "lerna bootstrap --use-workspaces",
1515
"release": "./release.sh"

packages/web-scripts/src/SharedTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type TestTaskDesc = {
2828
export type LintTaskDesc = {
2929
name: 'lint';
3030
config: string;
31+
typecheck: boolean;
3132
} & TaskDesc;
3233

3334
export type CommitTaskDesc = {

packages/web-scripts/src/Tasks/LintTask.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
import { LintTaskDesc } from '../SharedTypes';
2-
import { default as spawn } from 'cross-spawn';
1+
import { default as spawn } from 'cross-spawn-promise';
32
import { default as Debug } from 'debug';
3+
4+
import { LintTaskDesc } from '../SharedTypes';
45
import { CONSUMING_ROOT } from '../Paths';
5-
import { SpawnSyncReturns } from 'child_process';
6+
67
const dbg = Debug('web-scripts:lint'); // eslint-disable-line new-cap
78

8-
export function lintTask(task: LintTaskDesc): SpawnSyncReturns<Buffer> {
9+
export async function lintTask(task: LintTaskDesc): Promise<string[]> {
10+
const fns = [eslintRun];
11+
if (task.typecheck) fns.push(typeCheck);
12+
13+
return await Promise.all(
14+
fns.map(async fn => {
15+
dbg('Beginning %s task', fn.name);
16+
const stdout = await fn(task);
17+
dbg('Finished %s task', fn.name);
18+
return stdout;
19+
}),
20+
);
21+
}
22+
23+
async function eslintRun(task: LintTaskDesc): Promise<string> {
924
const cmd = 'npx';
1025
const args = [
1126
'--no-install',
@@ -24,5 +39,14 @@ export function lintTask(task: LintTaskDesc): SpawnSyncReturns<Buffer> {
2439
...task.restOptions,
2540
];
2641
dbg('npx args %o', args);
27-
return spawn.sync(cmd, args, { stdio: 'inherit' });
42+
43+
const stdout = await spawn(cmd, args, { stdio: 'inherit' });
44+
return (stdout || '').toString();
45+
}
46+
47+
async function typeCheck(): Promise<string> {
48+
const cmd = 'npx';
49+
const args = ['tsc', '--noEmit'];
50+
const stdout = await spawn(cmd, args, { stdio: 'inherit' });
51+
return (stdout || '').toString();
2852
}

packages/web-scripts/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,19 @@ program
7373
program
7474
.command('lint')
7575
.allowUnknownOption()
76-
.description('Run eslint')
76+
.description('Run ESLint and TypeScript to statically analyze your code')
7777
.option('--config [path]', 'path to ESLint config', ESLINT_CONFIG)
78+
.option('--typecheck', 'run a TypeScript type check')
7879
.action((cmd: Command) => {
79-
const { config } = cmd.opts();
80+
const { typecheck, config } = cmd.opts();
8081
const t: LintTaskDesc = {
8182
name: 'lint',
8283
config,
84+
typecheck,
8385
restOptions: parseRestOptions(cmd),
8486
};
8587

86-
handleSpawnResult(lintTask(t));
88+
handlePromiseResult(lintTask(t));
8789
});
8890

8991
program

packages/web-scripts/src/integration.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('integration tests', () => {
7878

7979
test(
8080
'Full integration test',
81-
async () => await testScripts(),
81+
async () => await testScripts([], ['--typecheck']),
8282
TEST_SCRIPTS_TIMEOUT,
8383
);
8484
});
@@ -163,15 +163,18 @@ describe('integration tests', () => {
163163
await exec('git init', { cwd: PKG_ROOT });
164164
}
165165

166-
async function testScripts(buildArgs: string[] = []) {
166+
async function testScripts(
167+
buildArgs: string[] = [],
168+
lintArgs: string[] = [],
169+
) {
167170
try {
168171
rimraf.sync(join(PKG_ROOT, 'cjs'));
169172
expect(existsSync(join(PKG_ROOT, 'cjs/index.js'))).toBe(false);
170173
await exec(['yarn build', ...buildArgs].join(' '), { cwd: PKG_ROOT });
171174
expect(existsSync(join(PKG_ROOT, 'cjs/index.js'))).toBe(true);
172175

173176
await exec('yarn test', { cwd: PKG_ROOT });
174-
await exec('yarn lint', { cwd: PKG_ROOT });
177+
await exec(['yarn lint', ...lintArgs].join(' '), { cwd: PKG_ROOT });
175178
} catch (e) {
176179
// We are not capturing and printing stdout above, where TSC prints its errors. This makes sure it's printed.
177180
console.log(e.stdout); // eslint-disable-line no-console

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,9 +5794,9 @@ lodash.without@~4.4.0:
57945794
integrity sha1-PNRXSgC2e643OpS3SHcmQFB7eqw=
57955795

57965796
lodash@4.17.11, lodash@>=4.17.12, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1:
5797-
version "4.17.14"
5798-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
5799-
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==
5797+
version "4.17.15"
5798+
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
5799+
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
58005800

58015801
log-symbols@^1.0.2:
58025802
version "1.0.2"
@@ -6161,7 +6161,7 @@ mississippi@^3.0.0:
61616161

61626162
mixin-deep@>=1.3.2, mixin-deep@^1.2.0:
61636163
version "2.0.1"
6164-
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-2.0.1.tgz#9a6946bef4a368401b784970ae3caaaa6bab02fa"
6164+
resolved "https://registry.npmjs.org/mixin-deep/-/mixin-deep-2.0.1.tgz#9a6946bef4a368401b784970ae3caaaa6bab02fa"
61656165
integrity sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA==
61666166

61676167
mkdirp@0.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
@@ -7965,7 +7965,7 @@ set-blocking@^2.0.0, set-blocking@~2.0.0:
79657965

79667966
set-value@>=3.0.1, set-value@^0.4.3, set-value@^2.0.0:
79677967
version "3.0.1"
7968-
resolved "https://registry.yarnpkg.com/set-value/-/set-value-3.0.1.tgz#52c82af7653ba69eb1db92e81f5cdb32739b9e95"
7968+
resolved "https://registry.npmjs.org/set-value/-/set-value-3.0.1.tgz#52c82af7653ba69eb1db92e81f5cdb32739b9e95"
79697969
integrity sha512-w6n3GUPYAWQj4ZyHWzD7K2FnFXHx9OTwJYbWg+6nXjG8sCLfs9DGv+KlqglKIIJx+ks7MlFuwFW2RBPb+8V+xg==
79707970
dependencies:
79717971
is-plain-object "^2.0.4"

0 commit comments

Comments
 (0)