|
| 1 | +const { readFileSync } = require('fs') |
| 2 | + |
| 3 | +const { parseForESLint } = require('@typescript-eslint/parser') |
| 4 | +const { Suite } = require('benchmark') |
| 5 | +const chalk = require('chalk') |
| 6 | +const { Linter, SourceCode } = require('eslint') |
| 7 | + |
| 8 | +const { lint } = require('../index') |
| 9 | + |
| 10 | +const suite = new Suite('Lint benchmark') |
| 11 | + |
| 12 | +const filepath = require.resolve('rxjs/src/internal/Subscriber.ts') |
| 13 | + |
| 14 | +const tsconfigPath = require.resolve('rxjs/src/tsconfig.json') |
| 15 | + |
| 16 | +const sourceCodeBuffer = readFileSync(filepath) |
| 17 | +const sourcecode = sourceCodeBuffer.toString('utf-8') |
| 18 | + |
| 19 | +const linter = new Linter() |
| 20 | + |
| 21 | +suite |
| 22 | + .add('@node-rs/deno-lint', () => { |
| 23 | + lint(filepath, sourceCodeBuffer) |
| 24 | + }) |
| 25 | + .add('eslint', () => { |
| 26 | + const parseForESLintResult = parseForESLint(sourcecode, { |
| 27 | + filePath: filepath, |
| 28 | + sourceType: 'module', |
| 29 | + ecmaVersion: 2019, |
| 30 | + project: tsconfigPath, |
| 31 | + loc: true, |
| 32 | + range: true, |
| 33 | + tokens: true, |
| 34 | + comment: true, |
| 35 | + }) |
| 36 | + |
| 37 | + const sc = new SourceCode({ |
| 38 | + text: sourcecode, |
| 39 | + ...parseForESLintResult, |
| 40 | + }) |
| 41 | + |
| 42 | + linter.verify(sc, {}, filepath) |
| 43 | + }) |
| 44 | + .on('cycle', function (event) { |
| 45 | + console.info(String(event.target)) |
| 46 | + }) |
| 47 | + .on('complete', function () { |
| 48 | + console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) |
| 49 | + }) |
| 50 | + .run() |
0 commit comments