-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
chore: run eslint with type information on CI #13368
Changes from 4 commits
4365f4c
dc9d080
8c7245d
9df68fe
930152c
4857a0e
883bbac
ee896fb
fdd1907
ca94f5c
1854014
d9b4f48
9fd782d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,10 +114,10 @@ const IDVisitor = { | |
], | ||
}; | ||
|
||
const FUNCTIONS: Record< | ||
const FUNCTIONS = Object.create(null) as Record< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
string, | ||
<T extends Node>(args: Array<NodePath<T>>) => boolean | ||
> = Object.create(null); | ||
>; | ||
|
||
FUNCTIONS.mock = args => { | ||
if (args.length === 1) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,6 @@ import toThrowMatchers, { | |
createMatcher as createThrowMatcher, | ||
} from './toThrowMatchers'; | ||
import type { | ||
AsyncExpectationResult, | ||
Expect, | ||
ExpectationResult, | ||
MatcherContext, | ||
|
@@ -363,19 +362,16 @@ const makeThrowingMatcher = ( | |
})(); | ||
|
||
if (isPromise(potentialResult)) { | ||
const asyncResult = potentialResult as AsyncExpectationResult; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only change to non-test code. The cast was unnecessary as TS could infer it from it being a promise |
||
const asyncError = new JestAssertionError(); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(asyncError, throwingMatcher); | ||
} | ||
|
||
return asyncResult | ||
return potentialResult | ||
.then(aResult => processResult(aResult, asyncError)) | ||
.catch(handleError); | ||
} else { | ||
const syncResult = potentialResult as SyncExpectationResult; | ||
|
||
return processResult(syncResult); | ||
return processResult(potentialResult); | ||
} | ||
} catch (error: any) { | ||
return handleError(error); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import * as url from 'url'; | ||
import chalk from 'chalk'; | ||
import {ESLint} from 'eslint'; | ||
import pLimit from 'p-limit'; | ||
import {getPackagesWithTsConfig} from './buildUtils.mjs'; | ||
|
||
// we want to limit the number of processes we spawn | ||
const cpus = Math.max(1, os.cpus().length - 1); | ||
const mutex = pLimit(cpus); | ||
|
||
const fix = process.argv.slice(2).some(arg => arg === '--fix'); | ||
|
||
const monorepoRoot = path.resolve(url.fileURLToPath(import.meta.url), '../..'); | ||
|
||
// TODO: remove this list at some point and run against all packages | ||
const packagesToTest = [ | ||
'babel-jest', | ||
'babel-plugin-jest-hoist', | ||
'diff-sequences', | ||
'jest-source-map', | ||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only four packages? That’s not su bad. It is indeed good idea to have this added! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a list of which we lint, not the ones excluded. running on e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah.. So that’s a good start then ;D |
||
]; | ||
|
||
const packagesWithTs = getPackagesWithTsConfig() | ||
.map(({packageDir}) => packageDir) | ||
.concat(path.resolve(monorepoRoot, 'e2e')) | ||
.filter(packageDir => packagesToTest.some(pkg => packageDir.endsWith(pkg))); | ||
|
||
try { | ||
await Promise.all( | ||
packagesWithTs.map(packageDir => | ||
mutex(async () => { | ||
const eslint = new ESLint({ | ||
cache: true, | ||
cacheLocation: path.resolve(packageDir, '.eslintcache'), | ||
cwd: monorepoRoot, | ||
extensions: ['.ts'], | ||
fix, | ||
overrideConfig: { | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: ['./tsconfig.json', `${packageDir}/tsconfig.json`], | ||
tsconfigRootDir: monorepoRoot, | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
root: true, | ||
}, | ||
}); | ||
|
||
const filesToLint = packageDir.endsWith('e2e') | ||
? `${packageDir}/__tests__/` | ||
: `${packageDir}/src/`; | ||
|
||
let results = await eslint.lintFiles(filesToLint); | ||
|
||
if (fix) { | ||
await ESLint.outputFixes(results); | ||
|
||
// re-run after outputting fixes | ||
results = await eslint.lintFiles(filesToLint); | ||
} | ||
|
||
const filteredResults = ESLint.getErrorResults(results); | ||
|
||
if (filteredResults.length > 0) { | ||
const formatter = await eslint.loadFormatter('stylish'); | ||
const resultText = formatter.format(results); | ||
|
||
console.error(resultText); | ||
|
||
throw new Error('Got lint errors'); | ||
} | ||
}), | ||
), | ||
); | ||
} catch (e) { | ||
console.error( | ||
chalk.inverse.red(' Unable to lint using TypeScript info files '), | ||
); | ||
|
||
throw e; | ||
} | ||
|
||
console.log( | ||
chalk.inverse.green(' Successfully linted using TypeScript info files '), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#13367 came from this 🙂