This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,11 @@
import webpack from 'webpack';
import { EsLintReporterOptions } from './EsLintReporterOptions';
import { CLIEngineOptions } from './types/eslint';
interface EsLintReporterConfiguration {
enabled: boolean;
memoryLimit: number;
options: CLIEngineOptions;
files: string[];
}
declare function createEsLintReporterConfiguration(compiler: webpack.Compiler, options: EsLintReporterOptions | undefined): EsLintReporterConfiguration;
export { EsLintReporterConfiguration, createEsLintReporterConfiguration };

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
function castToArray(value) {
if (!value) {
return [];
}
else if (!Array.isArray(value)) {
return [value];
}
else {
return value;
}
}
function createEsLintReporterConfiguration(compiler, options) {
const filesPatterns = (typeof options === 'object' ? castToArray(options.files) : []).map((filesPattern) =>
// ensure that `filesPattern` is an absolute path
path_1.isAbsolute(filesPattern)
? filesPattern
: path_1.join(compiler.options.context || process.cwd(), filesPattern));
return Object.assign(Object.assign({ enabled: !!options &&
typeof options !== 'boolean' &&
filesPatterns.length > 0 && // enable by default if files are provided
options.enabled !== false, memoryLimit: 2048 }, (typeof options === 'object' ? options : {})), { files: filesPatterns, options: Object.assign({ cwd: compiler.options.context || process.cwd(), extensions: ['.ts', '.tsx', '.js', '.jsx'] }, (typeof options === 'object' ? options.options || {} : {})) });
}
exports.createEsLintReporterConfiguration = createEsLintReporterConfiguration;

View File

@@ -0,0 +1,8 @@
import { CLIEngineOptions } from './types/eslint';
declare type EsLintReporterOptions = {
files: string | string[];
enabled?: boolean;
memoryLimit?: number;
options?: CLIEngineOptions;
};
export { EsLintReporterOptions };

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,3 @@
import { EsLintReporterConfiguration } from './EsLintReporterConfiguration';
declare function assertEsLintSupport(configuration: EsLintReporterConfiguration): void;
export { assertEsLintSupport };

View File

@@ -0,0 +1,30 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const semver = __importStar(require("semver"));
function assertEsLintSupport(configuration) {
if (semver.lt(process.version, '8.10.0')) {
throw new Error(`To use 'eslint' option, please update to Node.js >= v8.10.0 ` +
`(current version is ${process.version})`);
}
let eslintVersion;
try {
eslintVersion = require('eslint').Linter.version;
}
catch (error) {
throw new Error(`When you use 'eslint' option, make sure to install 'eslint'.`);
}
if (semver.lt(eslintVersion, '6.0.0')) {
throw new Error(`Cannot use current eslint version of ${eslintVersion}, the minimum required version is 6.0.0`);
}
if (!configuration.files) {
throw new Error('The `eslint.files` settings is required for EsLint reporter to work.');
}
}
exports.assertEsLintSupport = assertEsLintSupport;

View File

@@ -0,0 +1,4 @@
import { Issue } from '../../issue';
import { LintResult } from '../types/eslint';
declare function createIssuesFromEsLintResults(results: LintResult[]): Issue[];
export { createIssuesFromEsLintResults };

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function createIssueFromEsLintMessage(filePath, message) {
let location;
if (message.line) {
location = {
start: {
line: message.line,
column: message.column,
},
end: {
line: message.endLine || message.line,
column: message.endColumn || message.column,
},
};
}
return {
origin: 'eslint',
code: message.ruleId ? String(message.ruleId) : '[unknown]',
severity: message.severity === 1 ? 'warning' : 'error',
message: message.message,
file: filePath,
location,
};
}
function createIssuesFromEsLintResults(results) {
return results.reduce((messages, result) => [
...messages,
...result.messages.map((message) => createIssueFromEsLintMessage(result.filePath, message)),
], []);
}
exports.createIssuesFromEsLintResults = createIssuesFromEsLintResults;

View File

@@ -0,0 +1,4 @@
import { EsLintReporterConfiguration } from '../EsLintReporterConfiguration';
import { Reporter } from '../../reporter';
declare function createEsLintReporter(configuration: EsLintReporterConfiguration): Reporter;
export { createEsLintReporter };

View File

@@ -0,0 +1,179 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const EsLintIssueFactory_1 = require("../issue/EsLintIssueFactory");
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const minimatch_1 = __importDefault(require("minimatch"));
const glob_1 = __importDefault(require("glob"));
const isOldCLIEngine = (eslint) => eslint.resolveFileGlobPatterns !== undefined;
function createEsLintReporter(configuration) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { CLIEngine, ESLint } = require('eslint');
const eslint = ESLint
? new ESLint(configuration.options)
: new CLIEngine(configuration.options);
let isInitialRun = true;
let isInitialGetFiles = true;
const lintResults = new Map();
const includedGlobPatterns = resolveFileGlobPatterns(configuration.files);
const includedFiles = new Set();
function isFileIncluded(path) {
return __awaiter(this, void 0, void 0, function* () {
return (!path.includes('node_modules') &&
includedGlobPatterns.some((pattern) => minimatch_1.default(path, pattern)) &&
!(yield eslint.isPathIgnored(path)));
});
}
function getFiles() {
return __awaiter(this, void 0, void 0, function* () {
if (isInitialGetFiles) {
isInitialGetFiles = false;
const resolvedGlobs = yield Promise.all(includedGlobPatterns.map((globPattern) => new Promise((resolve) => {
glob_1.default(globPattern, (error, resolvedFiles) => {
if (error) {
// fail silently
resolve([]);
}
else {
resolve(resolvedFiles || []);
}
});
})));
for (const resolvedGlob of resolvedGlobs) {
for (const resolvedFile of resolvedGlob) {
if (yield isFileIncluded(resolvedFile)) {
includedFiles.add(resolvedFile);
}
}
}
}
return Array.from(includedFiles);
});
}
function getDirs() {
return includedGlobPatterns || [];
}
function getExtensions() {
return configuration.options.extensions || [];
}
// Copied from the eslint 6 implementation, as it's not available in eslint 8
function resolveFileGlobPatterns(globPatterns) {
if (configuration.options.globInputPaths === false) {
return globPatterns.filter(Boolean);
}
const extensions = getExtensions().map((ext) => ext.replace(/^\./u, ''));
const dirSuffix = `/**/*.{${extensions.join(',')}}`;
return globPatterns.filter(Boolean).map((globPattern) => {
const resolvedPath = path_1.default.resolve(configuration.options.cwd || '', globPattern);
const newPath = directoryExists(resolvedPath)
? globPattern.replace(/[/\\]$/u, '') + dirSuffix
: globPattern;
return path_1.default.normalize(newPath).replace(/\\/gu, '/');
});
}
// Copied from the eslint 6 implementation, as it's not available in eslint 8
function directoryExists(resolvedPath) {
try {
return fs_extra_1.default.statSync(resolvedPath).isDirectory();
}
catch (error) {
if (error && error.code === 'ENOENT') {
return false;
}
throw error;
}
}
return {
getReport: ({ changedFiles = [], deletedFiles = [] }) => __awaiter(this, void 0, void 0, function* () {
return {
getDependencies() {
return __awaiter(this, void 0, void 0, function* () {
for (const changedFile of changedFiles) {
if (yield isFileIncluded(changedFile)) {
includedFiles.add(changedFile);
}
}
for (const deletedFile of deletedFiles) {
includedFiles.delete(deletedFile);
}
return {
files: (yield getFiles()).map((file) => path_1.default.normalize(file)),
dirs: getDirs().map((dir) => path_1.default.normalize(dir)),
excluded: [],
extensions: getExtensions(),
};
});
},
getIssues() {
return __awaiter(this, void 0, void 0, function* () {
// cleanup old results
for (const changedFile of changedFiles) {
lintResults.delete(changedFile);
}
for (const deletedFile of deletedFiles) {
lintResults.delete(deletedFile);
}
// get reports
const lintReports = [];
if (isInitialRun) {
const lintReport = yield (isOldCLIEngine(eslint)
? Promise.resolve(eslint.executeOnFiles(includedGlobPatterns))
: eslint.lintFiles(includedGlobPatterns).then((results) => ({ results })));
lintReports.push(lintReport);
isInitialRun = false;
}
else {
// we need to take care to not lint files that are not included by the configuration.
// the eslint engine will not exclude them automatically
const changedAndIncludedFiles = [];
for (const changedFile of changedFiles) {
if (yield isFileIncluded(changedFile)) {
changedAndIncludedFiles.push(changedFile);
}
}
if (changedAndIncludedFiles.length) {
const lintReport = yield (isOldCLIEngine(eslint)
? Promise.resolve(eslint.executeOnFiles(changedAndIncludedFiles))
: eslint.lintFiles(changedAndIncludedFiles).then((results) => ({ results })));
lintReports.push(lintReport);
}
}
// output fixes if `fix` option is provided
if (configuration.options.fix) {
yield Promise.all(lintReports.map((lintReport) => isOldCLIEngine(eslint)
? CLIEngine.outputFixes(lintReport)
: ESLint.outputFixes(lintReport.results)));
}
// store results
for (const lintReport of lintReports) {
for (const lintResult of lintReport.results) {
lintResults.set(lintResult.filePath, lintResult);
}
}
// get actual list of previous and current reports
const results = Array.from(lintResults.values());
return EsLintIssueFactory_1.createIssuesFromEsLintResults(results);
});
},
close() {
return __awaiter(this, void 0, void 0, function* () {
// do nothing
});
},
};
}),
};
}
exports.createEsLintReporter = createEsLintReporter;

View File

@@ -0,0 +1,4 @@
import { EsLintReporterConfiguration } from '../EsLintReporterConfiguration';
import { ReporterRpcClient } from '../../reporter';
declare function createEsLintReporterRpcClient(configuration: EsLintReporterConfiguration): ReporterRpcClient;
export { createEsLintReporterRpcClient };

View File

@@ -0,0 +1,13 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const reporter_1 = require("../../reporter");
const rpc_ipc_1 = require("../../rpc/rpc-ipc");
function createEsLintReporterRpcClient(configuration) {
const channel = rpc_ipc_1.createRpcIpcMessageChannel(path_1.default.resolve(__dirname, './EsLintReporterRpcService.js'), configuration.memoryLimit);
return reporter_1.createReporterRpcClient(channel, configuration);
}
exports.createEsLintReporterRpcClient = createEsLintReporterRpcClient;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const process_1 = __importDefault(require("process"));
const EsLintReporter_1 = require("./EsLintReporter");
const reporter_1 = require("../../reporter");
const rpc_ipc_1 = require("../../rpc/rpc-ipc");
const service = reporter_1.registerReporterRpcService(rpc_ipc_1.createRpcIpcMessagePort(process_1.default), EsLintReporter_1.createEsLintReporter);
service.open();

View File

@@ -0,0 +1,37 @@
export interface LintMessage {
ruleId: string | null;
severity: number;
message: string;
line: number;
column: number;
endColumn?: number;
endLine?: number;
[key: string]: any;
}
export interface LintResult {
filePath: string;
messages: LintMessage[];
[key: string]: any;
}
export interface LintReport {
results: LintResult[];
[key: string]: any;
}
export interface CLIEngine {
version: string;
executeOnFiles(filesPatterns: string[]): LintReport;
resolveFileGlobPatterns(filesPatterns: string[]): string[];
isPathIgnored(filePath: string): boolean;
}
export interface ESLint {
version: string;
lintFiles(filesPatterns: string[]): Promise<LintResult[]>;
isPathIgnored(filePath: string): Promise<boolean>;
}
export declare type ESLintOrCLIEngine = CLIEngine | ESLint;
export interface CLIEngineOptions {
cwd?: string;
extensions?: string[];
fix?: boolean;
[key: string]: any;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });