-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Script static checkers + precommit #77900
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
//eslint-disable-next-line import/no-extraneous-dependencies | ||
const { CLIEngine } = require('eslint'); | ||
const { resolve } = require('path'); | ||
//eslint-disable-next-line import/no-extraneous-dependencies | ||
const { argv } = require('yargs'); | ||
|
||
async function run() { | ||
const fix = !!argv.fix; | ||
|
||
const engine = new CLIEngine({ | ||
fix, | ||
cache: true, | ||
extensions: ['.js', '.jsx', '.ts', '.tsx'], | ||
}); | ||
|
||
const report = engine.executeOnFiles(resolve(__dirname, '..')); | ||
|
||
const formatter = engine.getFormatter(); | ||
|
||
return formatter(report.results); | ||
} | ||
|
||
run() | ||
.then((text) => { | ||
//eslint-disable-next-line no-console | ||
console.log(text); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
/* | ||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||||||
* or more contributor license agreements. Licensed under the Elastic License; | ||||||
* you may not use this file except in compliance with the Elastic License. | ||||||
*/ | ||||||
// eslint-disable-next-line import/no-extraneous-dependencies | ||||||
require('@babel/register')({ | ||||||
extensions: ['.js'], | ||||||
plugins: [], | ||||||
presets: [ | ||||||
'@babel/typescript', | ||||||
['@babel/preset-env', { targets: { node: 'current' } }], | ||||||
], | ||||||
}); | ||||||
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies | ||||||
const { run } = require('jest'); | ||||||
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'test'; | ||||||
|
||||||
const config = require('../jest.config.js'); | ||||||
|
||||||
const argv = [...process.argv.slice(2), '--config', JSON.stringify(config)]; | ||||||
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. Looks like this could/should be a path
Suggested change
(might have to do something with 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. It's the same approach as the top-level jest test runner uses. |
||||||
|
||||||
run(argv); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* eslint-disable no-console*/ | ||
/* eslint-disable import/no-extraneous-dependencies*/ | ||
|
||
const execa = require('execa'); | ||
const Listr = require('listr'); | ||
const { resolve } = require('path'); | ||
|
||
const cwd = resolve(__dirname, '../../../..'); | ||
|
||
const execaOpts = { cwd, stderr: 'pipe' }; | ||
|
||
const tasks = new Listr( | ||
[ | ||
{ | ||
title: 'Jest', | ||
task: () => | ||
execa( | ||
'node', | ||
[ | ||
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. Could we just do 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. Is that the same as running |
||
resolve(__dirname, './jest.js'), | ||
'--reporters', | ||
resolve(__dirname, './node_modules/jest-silent-reporter'), | ||
'--collect-coverage', | ||
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. If this is just for precommit we might want to turn off coverage 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. done |
||
'false', | ||
], | ||
execaOpts | ||
), | ||
}, | ||
{ | ||
title: 'Typescript', | ||
task: () => | ||
execa('node', [resolve(__dirname, 'optimize-tsconfig.js')]).then(() => | ||
execa( | ||
require.resolve('typescript/bin/tsc'), | ||
[ | ||
'--project', | ||
resolve(__dirname, '../../../tsconfig.json'), | ||
'--pretty', | ||
'--noEmit', | ||
'--skipLibCheck', | ||
], | ||
execaOpts | ||
) | ||
), | ||
}, | ||
{ | ||
title: 'Lint', | ||
task: () => execa('node', [resolve(__dirname, 'eslint.js')], execaOpts), | ||
}, | ||
], | ||
{ exitOnError: false, concurrent: true } | ||
); | ||
|
||
tasks.run().catch((error) => { | ||
// from src/dev/typescript/exec_in_projects.ts | ||
process.exitCode = 1; | ||
|
||
const errors = error.errors || [error]; | ||
|
||
for (const e of errors) { | ||
process.stderr.write(e.stdout); | ||
} | ||
}); |
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.
Does this automatically find the right eslintrc?
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.
Yeah, looks like it.