-
-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4365f4c
chore: run eslint with type information on CI
SimenB dc9d080
use allowlist
SimenB 8c7245d
do jest-source-map as well
SimenB 9df68fe
add todo [skip ci]
SimenB 930152c
collect all results into a single output
SimenB 4857a0e
apply autofixes
SimenB 883bbac
fix all types of issues [skip ci]
SimenB ee896fb
more rules
SimenB fdd1907
apply fixes to all modules
SimenB ca94f5c
move comment [skip ci]
SimenB 1854014
snaps
SimenB d9b4f48
properly tear down env before waiting for logs
SimenB 9fd782d
line number fix
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* 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), '../..'); | ||
|
||
const packagesWithTs = getPackagesWithTsConfig() | ||
.map(({packageDir}) => packageDir) | ||
.concat(path.resolve(monorepoRoot, 'e2e')) | ||
// TODO: run all all projects | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.slice(0, 3); | ||
|
||
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 '), | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 🙂