@teambit/eslint 1.0.106 → 1.0.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint.composition.d.ts +2 -2
- package/dist/eslint.linter.js +2 -4
- package/dist/eslint.linter.js.map +1 -1
- package/dist/eslint.main.runtime.d.ts +4 -4
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/eslint.aspect.ts +5 -0
- package/eslint.linter.ts +258 -0
- package/eslint.main.runtime.ts +112 -0
- package/index.ts +10 -0
- package/package.json +15 -21
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Logo: () =>
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Logo: () => JSX.Element;
|
package/dist/eslint.linter.js
CHANGED
|
@@ -71,19 +71,17 @@ class ESLintLinter {
|
|
|
71
71
|
const longProcessLogger = this.logger.createLongProcessLogger('linting components', context.components.length);
|
|
72
72
|
const eslint = this.createEslint(this.options.config, this.ESLint);
|
|
73
73
|
if (this.options.tsConfig && context.rootDir) {
|
|
74
|
-
var _this$options;
|
|
75
74
|
const tsConfigPath = this.createTempTsConfigFile(context.rootDir, context.componentsDirMap, context.envRuntime.id, this.options.tsConfig);
|
|
76
|
-
if (
|
|
75
|
+
if (this.options?.config?.overrideConfig?.parserOptions) {
|
|
77
76
|
this.options.config.overrideConfig.parserOptions.project = tsConfigPath;
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
const resultsP = (0, _pMapSeries().default)(context.components, async component => {
|
|
81
80
|
longProcessLogger.logProgress(`component: ${component.id.toString()}, # of files: ${component.filesystem.files.length}`);
|
|
82
81
|
const filesP = component.filesystem.files.map(async file => {
|
|
83
|
-
var _this$options$extensi;
|
|
84
82
|
// TODO: now that we moved to lint files, maybe it's not required anymore
|
|
85
83
|
// The eslint api will not ignore extensions by default when using lintText, so we do it manually
|
|
86
|
-
if (!
|
|
84
|
+
if (!this.options.extensions?.includes(file.extname)) return undefined;
|
|
87
85
|
return file.path;
|
|
88
86
|
});
|
|
89
87
|
const files = (0, _lodash().compact)(await Promise.all(filesP));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_lodash","_eslint","_pMapSeries","_objectHash","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","ESLintLinter","constructor","logger","options","ESLint","displayConfig","JSON","stringify","lint","context","longProcessLogger","createLongProcessLogger","components","eslint","createEslint","config","tsConfig","rootDir","_this$options","tsConfigPath","createTempTsConfigFile","componentsDirMap","envRuntime","id","overrideConfig","parserOptions","project","resultsP","mapSeries","component","logProgress","toString","filesystem","files","filesP","map","file","_this$options$extensi","extensions","includes","extname","undefined","path","compact","Promise","all","lintResults","lintFiles","fix","ESLintLib","outputFixes","results","flatten","formatter","loadFormatter","output","format","totalErrorCount","totalFatalErrorCount","totalFixableErrorCount","totalFixableWarningCount","totalWarningCount","componentsResults","computeComponentResultsWithTotals","totalComponentsWithErrorCount","totalComponentsWithFatalErrorCount","totalComponentsWithFixableErrorCount","totalComponentsWithFixableWarningCount","totalComponentsWithWarningCount","computeManyComponentsTotals","errors","componentDirMap","envId","newTsConfig","compDirs","toArray","compDir","include","includedPath","exclude","excludedPath","cacheDir","getCacheDir","hash","objectHash","tempTsConfigPath","join","fs","existsSync","outputJSONSync","spaces","result","errorCount","fatalErrorCount","fixableErrorCount","fixableWarningCount","warningCount","filePath","messages","raw","ESLintModule","version","exports"],"sources":["eslint.linter.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport { flatten, compact } from 'lodash';\nimport { Linter, LinterContext, LintResults, ComponentLintResult } from '@teambit/linter';\nimport { ESLint as ESLintLib } from 'eslint';\nimport mapSeries from 'p-map-series';\nimport objectHash from 'object-hash';\nimport { ComponentMap } from '@teambit/component';\nimport { Logger } from '@teambit/logger';\nimport { ESLintOptions } from './eslint.main.runtime';\n\nexport class ESLintLinter implements Linter {\n constructor(\n private logger: Logger,\n\n private options: ESLintOptions,\n\n /**\n * reference to the eslint module.\n */\n private ESLint?: any\n ) {}\n\n id = 'eslint-linter';\n displayName = 'ESlint';\n\n displayConfig() {\n return JSON.stringify(this.options, null, 2);\n }\n\n async lint(context: LinterContext): Promise<LintResults> {\n const longProcessLogger = this.logger.createLongProcessLogger('linting components', context.components.length);\n const eslint = this.createEslint(this.options.config, this.ESLint);\n if (this.options.tsConfig && context.rootDir) {\n const tsConfigPath = this.createTempTsConfigFile(\n context.rootDir,\n context.componentsDirMap,\n context.envRuntime.id,\n this.options.tsConfig\n );\n if (this.options?.config?.overrideConfig?.parserOptions) {\n this.options.config.overrideConfig.parserOptions.project = tsConfigPath;\n }\n }\n const resultsP = mapSeries(context.components, async (component) => {\n longProcessLogger.logProgress(\n `component: ${component.id.toString()}, # of files: ${component.filesystem.files.length}`\n );\n const filesP = component.filesystem.files.map(async (file) => {\n // TODO: now that we moved to lint files, maybe it's not required anymore\n // The eslint api will not ignore extensions by default when using lintText, so we do it manually\n if (!this.options.extensions?.includes(file.extname)) return undefined;\n return file.path;\n });\n\n const files = compact(await Promise.all(filesP));\n const lintResults = await eslint.lintFiles(files);\n\n if (eslint && this.options.config.fix && lintResults) {\n await ESLintLib.outputFixes(lintResults);\n }\n\n const results: ESLintLib.LintResult[] = compact(flatten(lintResults));\n const formatter = await eslint.loadFormatter(this.options.formatter || 'stylish');\n const output = formatter.format(results);\n const {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n } = this.computeComponentResultsWithTotals(results);\n\n return {\n component,\n output,\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n results: componentsResults,\n };\n });\n\n const results = (await resultsP) as any as ComponentLintResult[];\n const {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n } = this.computeManyComponentsTotals(results);\n\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n results,\n errors: [],\n };\n }\n\n private createTempTsConfigFile(\n rootDir: string,\n componentDirMap: ComponentMap<string>,\n envId: string,\n tsConfig: Record<string, any>\n ): string {\n const newTsConfig = {\n ...tsConfig,\n };\n const compDirs: string[] = componentDirMap.toArray().map(([, compDir]) => compDir);\n if (tsConfig.include) {\n newTsConfig.include = flatten(\n tsConfig.include.map((includedPath) => {\n return compDirs.map((compDir) => `../../${compDir}/${includedPath}`);\n })\n );\n }\n if (tsConfig.exclude) {\n newTsConfig.exclude = flatten(\n tsConfig.exclude.map((excludedPath) => {\n return compDirs.map((compDir) => `../../${compDir}/${excludedPath}`);\n })\n );\n }\n const cacheDir = getCacheDir(rootDir);\n const hash = objectHash(newTsConfig);\n // We save the tsconfig with hash here to avoid creating unnecessary tsconfig files\n // this is very important as eslint will be able to cache the tsconfig file and will not need to create another program\n // this affects performance dramatically\n const tempTsConfigPath = path.join(cacheDir, `bit.tsconfig.eslint.${hash}.json`);\n if (!fs.existsSync(tempTsConfigPath)) {\n fs.outputJSONSync(tempTsConfigPath, newTsConfig, { spaces: 2 });\n }\n return tempTsConfigPath;\n }\n\n private computeComponentResultsWithTotals(results: ESLintLib.LintResult[]) {\n let totalErrorCount = 0;\n let totalFatalErrorCount = 0;\n let totalFixableErrorCount = 0;\n let totalFixableWarningCount = 0;\n let totalWarningCount = 0;\n const componentsResults = results.map((result) => {\n totalErrorCount += result.errorCount ?? 0;\n // @ts-ignore - missing from the @types/eslint lib\n totalFatalErrorCount += result.fatalErrorCount ?? 0;\n totalFixableErrorCount += result.fixableErrorCount ?? 0;\n totalFixableWarningCount += result.fixableWarningCount ?? 0;\n totalWarningCount += result.warningCount ?? 0;\n return {\n filePath: result.filePath,\n errorCount: result.errorCount,\n // @ts-ignore - missing from the @types/eslint lib\n fatalErrorCount: result.fatalErrorCount,\n fixableErrorCount: result.fixableErrorCount,\n fixableWarningCount: result.fixableWarningCount,\n warningCount: result.warningCount,\n messages: result.messages,\n raw: result,\n };\n });\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n };\n }\n\n private computeManyComponentsTotals(componentsResults: ComponentLintResult[]) {\n let totalErrorCount = 0;\n let totalFatalErrorCount = 0;\n let totalFixableErrorCount = 0;\n let totalFixableWarningCount = 0;\n let totalWarningCount = 0;\n let totalComponentsWithErrorCount = 0;\n let totalComponentsWithFatalErrorCount = 0;\n let totalComponentsWithFixableErrorCount = 0;\n let totalComponentsWithFixableWarningCount = 0;\n let totalComponentsWithWarningCount = 0;\n\n componentsResults.forEach((result) => {\n if (result.totalErrorCount) {\n totalErrorCount += result.totalErrorCount;\n totalComponentsWithErrorCount += 1;\n }\n // @ts-ignore - missing from the @types/eslint lib\n if (result.totalFatalErrorCount) {\n totalFatalErrorCount += result.totalFatalErrorCount;\n totalComponentsWithFatalErrorCount += 1;\n }\n if (result.totalFixableErrorCount) {\n totalFixableErrorCount += result.totalFixableErrorCount;\n totalComponentsWithFixableErrorCount += 1;\n }\n if (result.totalFixableWarningCount) {\n totalFixableWarningCount += result.totalFixableWarningCount;\n totalComponentsWithFixableWarningCount += 1;\n }\n if (result.totalWarningCount) {\n totalWarningCount += result.totalWarningCount;\n totalComponentsWithWarningCount += 1;\n }\n });\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n };\n }\n\n /**\n * Create the eslint instance by options that was already merged with context\n * @param options\n * @param ESLintModule\n * @returns\n */\n private createEslint(options: ESLintLib.Options, ESLintModule?: any): ESLintLib {\n // eslint-disable-next-line no-new\n if (ESLintModule) new ESLintModule.ESLint(options);\n return new ESLintLib(options);\n }\n\n version() {\n if (this.ESLint) return this.ESLint.version;\n return ESLintLib.version;\n }\n}\n\nfunction getCacheDir(rootDir): string {\n return path.join(rootDir, 'node_modules', '.cache');\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,YAAA;EAAA,MAAAN,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OA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AiB;MACjBE,6BAA6B;MAC7BC,kCAAkC;MAClCC,oCAAoC;MACpCC,sCAAsC;MACtCC;IACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;EACUtD,YAAYA,CAACX,OAA0B,EAAEiG,YAAkB,EAAa;IAC9E;IACA,IAAIA,YAAY,EAAE,IAAIA,YAAY,CAAChG,MAAM,CAACD,OAAO,CAAC;IAClD,OAAO,KAAI8C,gBAAS,EAAC9C,OAAO,CAAC;EAC/B;EAEAkG,OAAOA,CAAA,EAAG;IACR,IAAI,IAAI,CAACjG,MAAM,EAAE,OAAO,IAAI,CAACA,MAAM,CAACiG,OAAO;IAC3C,OAAOpD,gBAAS,CAACoD,OAAO;EAC1B;AACF;AAACC,OAAA,CAAAtG,YAAA,GAAAA,YAAA;AAED,SAASkF,WAAWA,CAACjE,OAAO,EAAU;EACpC,OAAOyB,eAAI,CAAC4C,IAAI,CAACrE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC;AACrD"}
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_lodash","_eslint","_pMapSeries","_objectHash","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","ESLintLinter","constructor","logger","options","ESLint","displayConfig","JSON","stringify","lint","context","longProcessLogger","createLongProcessLogger","components","eslint","createEslint","config","tsConfig","rootDir","tsConfigPath","createTempTsConfigFile","componentsDirMap","envRuntime","id","overrideConfig","parserOptions","project","resultsP","mapSeries","component","logProgress","toString","filesystem","files","filesP","map","file","extensions","includes","extname","undefined","path","compact","Promise","all","lintResults","lintFiles","fix","ESLintLib","outputFixes","results","flatten","formatter","loadFormatter","output","format","totalErrorCount","totalFatalErrorCount","totalFixableErrorCount","totalFixableWarningCount","totalWarningCount","componentsResults","computeComponentResultsWithTotals","totalComponentsWithErrorCount","totalComponentsWithFatalErrorCount","totalComponentsWithFixableErrorCount","totalComponentsWithFixableWarningCount","totalComponentsWithWarningCount","computeManyComponentsTotals","errors","componentDirMap","envId","newTsConfig","compDirs","toArray","compDir","include","includedPath","exclude","excludedPath","cacheDir","getCacheDir","hash","objectHash","tempTsConfigPath","join","fs","existsSync","outputJSONSync","spaces","result","errorCount","fatalErrorCount","fixableErrorCount","fixableWarningCount","warningCount","filePath","messages","raw","ESLintModule","version","exports"],"sources":["eslint.linter.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport { flatten, compact } from 'lodash';\nimport { Linter, LinterContext, LintResults, ComponentLintResult } from '@teambit/linter';\nimport { ESLint as ESLintLib } from 'eslint';\nimport mapSeries from 'p-map-series';\nimport objectHash from 'object-hash';\nimport { ComponentMap } from '@teambit/component';\nimport { Logger } from '@teambit/logger';\nimport { ESLintOptions } from './eslint.main.runtime';\n\nexport class ESLintLinter implements Linter {\n constructor(\n private logger: Logger,\n\n private options: ESLintOptions,\n\n /**\n * reference to the eslint module.\n */\n private ESLint?: any\n ) {}\n\n id = 'eslint-linter';\n displayName = 'ESlint';\n\n displayConfig() {\n return JSON.stringify(this.options, null, 2);\n }\n\n async lint(context: LinterContext): Promise<LintResults> {\n const longProcessLogger = this.logger.createLongProcessLogger('linting components', context.components.length);\n const eslint = this.createEslint(this.options.config, this.ESLint);\n if (this.options.tsConfig && context.rootDir) {\n const tsConfigPath = this.createTempTsConfigFile(\n context.rootDir,\n context.componentsDirMap,\n context.envRuntime.id,\n this.options.tsConfig\n );\n if (this.options?.config?.overrideConfig?.parserOptions) {\n this.options.config.overrideConfig.parserOptions.project = tsConfigPath;\n }\n }\n const resultsP = mapSeries(context.components, async (component) => {\n longProcessLogger.logProgress(\n `component: ${component.id.toString()}, # of files: ${component.filesystem.files.length}`\n );\n const filesP = component.filesystem.files.map(async (file) => {\n // TODO: now that we moved to lint files, maybe it's not required anymore\n // The eslint api will not ignore extensions by default when using lintText, so we do it manually\n if (!this.options.extensions?.includes(file.extname)) return undefined;\n return file.path;\n });\n\n const files = compact(await Promise.all(filesP));\n const lintResults = await eslint.lintFiles(files);\n\n if (eslint && this.options.config.fix && lintResults) {\n await ESLintLib.outputFixes(lintResults);\n }\n\n const results: ESLintLib.LintResult[] = compact(flatten(lintResults));\n const formatter = await eslint.loadFormatter(this.options.formatter || 'stylish');\n const output = formatter.format(results);\n const {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n } = this.computeComponentResultsWithTotals(results);\n\n return {\n component,\n output,\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n results: componentsResults,\n };\n });\n\n const results = (await resultsP) as any as ComponentLintResult[];\n const {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n } = this.computeManyComponentsTotals(results);\n\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n results,\n errors: [],\n };\n }\n\n private createTempTsConfigFile(\n rootDir: string,\n componentDirMap: ComponentMap<string>,\n envId: string,\n tsConfig: Record<string, any>\n ): string {\n const newTsConfig = {\n ...tsConfig,\n };\n const compDirs: string[] = componentDirMap.toArray().map(([, compDir]) => compDir);\n if (tsConfig.include) {\n newTsConfig.include = flatten(\n tsConfig.include.map((includedPath) => {\n return compDirs.map((compDir) => `../../${compDir}/${includedPath}`);\n })\n );\n }\n if (tsConfig.exclude) {\n newTsConfig.exclude = flatten(\n tsConfig.exclude.map((excludedPath) => {\n return compDirs.map((compDir) => `../../${compDir}/${excludedPath}`);\n })\n );\n }\n const cacheDir = getCacheDir(rootDir);\n const hash = objectHash(newTsConfig);\n // We save the tsconfig with hash here to avoid creating unnecessary tsconfig files\n // this is very important as eslint will be able to cache the tsconfig file and will not need to create another program\n // this affects performance dramatically\n const tempTsConfigPath = path.join(cacheDir, `bit.tsconfig.eslint.${hash}.json`);\n if (!fs.existsSync(tempTsConfigPath)) {\n fs.outputJSONSync(tempTsConfigPath, newTsConfig, { spaces: 2 });\n }\n return tempTsConfigPath;\n }\n\n private computeComponentResultsWithTotals(results: ESLintLib.LintResult[]) {\n let totalErrorCount = 0;\n let totalFatalErrorCount = 0;\n let totalFixableErrorCount = 0;\n let totalFixableWarningCount = 0;\n let totalWarningCount = 0;\n const componentsResults = results.map((result) => {\n totalErrorCount += result.errorCount ?? 0;\n // @ts-ignore - missing from the @types/eslint lib\n totalFatalErrorCount += result.fatalErrorCount ?? 0;\n totalFixableErrorCount += result.fixableErrorCount ?? 0;\n totalFixableWarningCount += result.fixableWarningCount ?? 0;\n totalWarningCount += result.warningCount ?? 0;\n return {\n filePath: result.filePath,\n errorCount: result.errorCount,\n // @ts-ignore - missing from the @types/eslint lib\n fatalErrorCount: result.fatalErrorCount,\n fixableErrorCount: result.fixableErrorCount,\n fixableWarningCount: result.fixableWarningCount,\n warningCount: result.warningCount,\n messages: result.messages,\n raw: result,\n };\n });\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n };\n }\n\n private computeManyComponentsTotals(componentsResults: ComponentLintResult[]) {\n let totalErrorCount = 0;\n let totalFatalErrorCount = 0;\n let totalFixableErrorCount = 0;\n let totalFixableWarningCount = 0;\n let totalWarningCount = 0;\n let totalComponentsWithErrorCount = 0;\n let totalComponentsWithFatalErrorCount = 0;\n let totalComponentsWithFixableErrorCount = 0;\n let totalComponentsWithFixableWarningCount = 0;\n let totalComponentsWithWarningCount = 0;\n\n componentsResults.forEach((result) => {\n if (result.totalErrorCount) {\n totalErrorCount += result.totalErrorCount;\n totalComponentsWithErrorCount += 1;\n }\n // @ts-ignore - missing from the @types/eslint lib\n if (result.totalFatalErrorCount) {\n totalFatalErrorCount += result.totalFatalErrorCount;\n totalComponentsWithFatalErrorCount += 1;\n }\n if (result.totalFixableErrorCount) {\n totalFixableErrorCount += result.totalFixableErrorCount;\n totalComponentsWithFixableErrorCount += 1;\n }\n if (result.totalFixableWarningCount) {\n totalFixableWarningCount += result.totalFixableWarningCount;\n totalComponentsWithFixableWarningCount += 1;\n }\n if (result.totalWarningCount) {\n totalWarningCount += result.totalWarningCount;\n totalComponentsWithWarningCount += 1;\n }\n });\n return {\n totalErrorCount,\n totalFatalErrorCount,\n totalFixableErrorCount,\n totalFixableWarningCount,\n totalWarningCount,\n componentsResults,\n totalComponentsWithErrorCount,\n totalComponentsWithFatalErrorCount,\n totalComponentsWithFixableErrorCount,\n totalComponentsWithFixableWarningCount,\n totalComponentsWithWarningCount,\n };\n }\n\n /**\n * Create the eslint instance by options that was already merged with context\n * @param options\n * @param ESLintModule\n * @returns\n */\n private createEslint(options: ESLintLib.Options, ESLintModule?: any): ESLintLib {\n // eslint-disable-next-line no-new\n if (ESLintModule) new ESLintModule.ESLint(options);\n return new ESLintLib(options);\n }\n\n version() {\n if (this.ESLint) return this.ESLint.version;\n return ESLintLib.version;\n }\n}\n\nfunction getCacheDir(rootDir): string {\n return path.join(rootDir, 'node_modules', '.cache');\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,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,IAAIwB,MAAM,CAAC9B,iBAAiB,EAAE;QAC5BA,iBAAiB,IAAI8B,MAAM,CAAC9B,iBAAiB;QAC7CO,+BAA+B,IAAI,CAAC;MACtC;IACF,CAAC,CAAC;IACF,OAAO;MACLX,eAAe;MACfC,oBAAoB;MACpBC,sBAAsB;MACtBC,wBAAwB;MACxBC,iBAAiB;MACjBC,iBAAiB;MACjBE,6BAA6B;MAC7BC,kCAAkC;MAClCC,oCAAoC;MACpCC,sCAAsC;MACtCC;IACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;EACUpD,YAAYA,CAACX,OAA0B,EAAE+F,YAAkB,EAAa;IAC9E;IACA,IAAIA,YAAY,EAAE,IAAIA,YAAY,CAAC9F,MAAM,CAACD,OAAO,CAAC;IAClD,OAAO,KAAI4C,gBAAS,EAAC5C,OAAO,CAAC;EAC/B;EAEAgG,OAAOA,CAAA,EAAG;IACR,IAAI,IAAI,CAAC/F,MAAM,EAAE,OAAO,IAAI,CAACA,MAAM,CAAC+F,OAAO;IAC3C,OAAOpD,gBAAS,CAACoD,OAAO;EAC1B;AACF;AAACC,OAAA,CAAApG,YAAA,GAAAA,YAAA;AAED,SAASgF,WAAWA,CAAC/D,OAAO,EAAU;EACpC,OAAOuB,eAAI,CAAC4C,IAAI,CAACnE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC;AACrD"}
|
|
@@ -3,7 +3,7 @@ import { Linter, LinterContext, LinterMain } from '@teambit/linter';
|
|
|
3
3
|
import { Logger, LoggerMain } from '@teambit/logger';
|
|
4
4
|
import { EslintConfigMutator } from '@teambit/defender.eslint.config-mutator';
|
|
5
5
|
import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
|
|
6
|
-
export
|
|
6
|
+
export type ESLintOptions = {
|
|
7
7
|
/**
|
|
8
8
|
* linter config for eslint.
|
|
9
9
|
*/
|
|
@@ -28,10 +28,10 @@ export declare type ESLintOptions = {
|
|
|
28
28
|
*/
|
|
29
29
|
tsConfig?: Record<string, any>;
|
|
30
30
|
};
|
|
31
|
-
export
|
|
31
|
+
export type EslintConfigTransformContext = {
|
|
32
32
|
fix: boolean;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export type EslintConfigTransformer = (config: EslintConfigMutator, context: EslintConfigTransformContext) => EslintConfigMutator;
|
|
35
35
|
export declare class ESLintMain {
|
|
36
36
|
private logger;
|
|
37
37
|
constructor(logger: Logger);
|
|
@@ -45,4 +45,4 @@ export declare class ESLintMain {
|
|
|
45
45
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
46
46
|
static provider([loggerExt]: [LoggerMain, WorkspaceConfigFilesMain, LinterMain]): Promise<ESLintMain>;
|
|
47
47
|
}
|
|
48
|
-
export declare function runTransformersWithContext(config: EslintConfigMutator, transformers: EslintConfigTransformer[]
|
|
48
|
+
export declare function runTransformersWithContext(config: EslintConfigMutator, transformers: EslintConfigTransformer[], context: EslintConfigTransformContext): EslintConfigMutator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.108/dist/eslint.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.108/dist/eslint.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/eslint.aspect.ts
ADDED
package/eslint.linter.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { flatten, compact } from 'lodash';
|
|
4
|
+
import { Linter, LinterContext, LintResults, ComponentLintResult } from '@teambit/linter';
|
|
5
|
+
import { ESLint as ESLintLib } from 'eslint';
|
|
6
|
+
import mapSeries from 'p-map-series';
|
|
7
|
+
import objectHash from 'object-hash';
|
|
8
|
+
import { ComponentMap } from '@teambit/component';
|
|
9
|
+
import { Logger } from '@teambit/logger';
|
|
10
|
+
import { ESLintOptions } from './eslint.main.runtime';
|
|
11
|
+
|
|
12
|
+
export class ESLintLinter implements Linter {
|
|
13
|
+
constructor(
|
|
14
|
+
private logger: Logger,
|
|
15
|
+
|
|
16
|
+
private options: ESLintOptions,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* reference to the eslint module.
|
|
20
|
+
*/
|
|
21
|
+
private ESLint?: any
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
id = 'eslint-linter';
|
|
25
|
+
displayName = 'ESlint';
|
|
26
|
+
|
|
27
|
+
displayConfig() {
|
|
28
|
+
return JSON.stringify(this.options, null, 2);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async lint(context: LinterContext): Promise<LintResults> {
|
|
32
|
+
const longProcessLogger = this.logger.createLongProcessLogger('linting components', context.components.length);
|
|
33
|
+
const eslint = this.createEslint(this.options.config, this.ESLint);
|
|
34
|
+
if (this.options.tsConfig && context.rootDir) {
|
|
35
|
+
const tsConfigPath = this.createTempTsConfigFile(
|
|
36
|
+
context.rootDir,
|
|
37
|
+
context.componentsDirMap,
|
|
38
|
+
context.envRuntime.id,
|
|
39
|
+
this.options.tsConfig
|
|
40
|
+
);
|
|
41
|
+
if (this.options?.config?.overrideConfig?.parserOptions) {
|
|
42
|
+
this.options.config.overrideConfig.parserOptions.project = tsConfigPath;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const resultsP = mapSeries(context.components, async (component) => {
|
|
46
|
+
longProcessLogger.logProgress(
|
|
47
|
+
`component: ${component.id.toString()}, # of files: ${component.filesystem.files.length}`
|
|
48
|
+
);
|
|
49
|
+
const filesP = component.filesystem.files.map(async (file) => {
|
|
50
|
+
// TODO: now that we moved to lint files, maybe it's not required anymore
|
|
51
|
+
// The eslint api will not ignore extensions by default when using lintText, so we do it manually
|
|
52
|
+
if (!this.options.extensions?.includes(file.extname)) return undefined;
|
|
53
|
+
return file.path;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const files = compact(await Promise.all(filesP));
|
|
57
|
+
const lintResults = await eslint.lintFiles(files);
|
|
58
|
+
|
|
59
|
+
if (eslint && this.options.config.fix && lintResults) {
|
|
60
|
+
await ESLintLib.outputFixes(lintResults);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const results: ESLintLib.LintResult[] = compact(flatten(lintResults));
|
|
64
|
+
const formatter = await eslint.loadFormatter(this.options.formatter || 'stylish');
|
|
65
|
+
const output = formatter.format(results);
|
|
66
|
+
const {
|
|
67
|
+
totalErrorCount,
|
|
68
|
+
totalFatalErrorCount,
|
|
69
|
+
totalFixableErrorCount,
|
|
70
|
+
totalFixableWarningCount,
|
|
71
|
+
totalWarningCount,
|
|
72
|
+
componentsResults,
|
|
73
|
+
} = this.computeComponentResultsWithTotals(results);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
component,
|
|
77
|
+
output,
|
|
78
|
+
totalErrorCount,
|
|
79
|
+
totalFatalErrorCount,
|
|
80
|
+
totalFixableErrorCount,
|
|
81
|
+
totalFixableWarningCount,
|
|
82
|
+
totalWarningCount,
|
|
83
|
+
results: componentsResults,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const results = (await resultsP) as any as ComponentLintResult[];
|
|
88
|
+
const {
|
|
89
|
+
totalErrorCount,
|
|
90
|
+
totalFatalErrorCount,
|
|
91
|
+
totalFixableErrorCount,
|
|
92
|
+
totalFixableWarningCount,
|
|
93
|
+
totalWarningCount,
|
|
94
|
+
totalComponentsWithErrorCount,
|
|
95
|
+
totalComponentsWithFatalErrorCount,
|
|
96
|
+
totalComponentsWithFixableErrorCount,
|
|
97
|
+
totalComponentsWithFixableWarningCount,
|
|
98
|
+
totalComponentsWithWarningCount,
|
|
99
|
+
} = this.computeManyComponentsTotals(results);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
totalErrorCount,
|
|
103
|
+
totalFatalErrorCount,
|
|
104
|
+
totalFixableErrorCount,
|
|
105
|
+
totalFixableWarningCount,
|
|
106
|
+
totalWarningCount,
|
|
107
|
+
totalComponentsWithErrorCount,
|
|
108
|
+
totalComponentsWithFatalErrorCount,
|
|
109
|
+
totalComponentsWithFixableErrorCount,
|
|
110
|
+
totalComponentsWithFixableWarningCount,
|
|
111
|
+
totalComponentsWithWarningCount,
|
|
112
|
+
results,
|
|
113
|
+
errors: [],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private createTempTsConfigFile(
|
|
118
|
+
rootDir: string,
|
|
119
|
+
componentDirMap: ComponentMap<string>,
|
|
120
|
+
envId: string,
|
|
121
|
+
tsConfig: Record<string, any>
|
|
122
|
+
): string {
|
|
123
|
+
const newTsConfig = {
|
|
124
|
+
...tsConfig,
|
|
125
|
+
};
|
|
126
|
+
const compDirs: string[] = componentDirMap.toArray().map(([, compDir]) => compDir);
|
|
127
|
+
if (tsConfig.include) {
|
|
128
|
+
newTsConfig.include = flatten(
|
|
129
|
+
tsConfig.include.map((includedPath) => {
|
|
130
|
+
return compDirs.map((compDir) => `../../${compDir}/${includedPath}`);
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (tsConfig.exclude) {
|
|
135
|
+
newTsConfig.exclude = flatten(
|
|
136
|
+
tsConfig.exclude.map((excludedPath) => {
|
|
137
|
+
return compDirs.map((compDir) => `../../${compDir}/${excludedPath}`);
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
const cacheDir = getCacheDir(rootDir);
|
|
142
|
+
const hash = objectHash(newTsConfig);
|
|
143
|
+
// We save the tsconfig with hash here to avoid creating unnecessary tsconfig files
|
|
144
|
+
// this is very important as eslint will be able to cache the tsconfig file and will not need to create another program
|
|
145
|
+
// this affects performance dramatically
|
|
146
|
+
const tempTsConfigPath = path.join(cacheDir, `bit.tsconfig.eslint.${hash}.json`);
|
|
147
|
+
if (!fs.existsSync(tempTsConfigPath)) {
|
|
148
|
+
fs.outputJSONSync(tempTsConfigPath, newTsConfig, { spaces: 2 });
|
|
149
|
+
}
|
|
150
|
+
return tempTsConfigPath;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private computeComponentResultsWithTotals(results: ESLintLib.LintResult[]) {
|
|
154
|
+
let totalErrorCount = 0;
|
|
155
|
+
let totalFatalErrorCount = 0;
|
|
156
|
+
let totalFixableErrorCount = 0;
|
|
157
|
+
let totalFixableWarningCount = 0;
|
|
158
|
+
let totalWarningCount = 0;
|
|
159
|
+
const componentsResults = results.map((result) => {
|
|
160
|
+
totalErrorCount += result.errorCount ?? 0;
|
|
161
|
+
// @ts-ignore - missing from the @types/eslint lib
|
|
162
|
+
totalFatalErrorCount += result.fatalErrorCount ?? 0;
|
|
163
|
+
totalFixableErrorCount += result.fixableErrorCount ?? 0;
|
|
164
|
+
totalFixableWarningCount += result.fixableWarningCount ?? 0;
|
|
165
|
+
totalWarningCount += result.warningCount ?? 0;
|
|
166
|
+
return {
|
|
167
|
+
filePath: result.filePath,
|
|
168
|
+
errorCount: result.errorCount,
|
|
169
|
+
// @ts-ignore - missing from the @types/eslint lib
|
|
170
|
+
fatalErrorCount: result.fatalErrorCount,
|
|
171
|
+
fixableErrorCount: result.fixableErrorCount,
|
|
172
|
+
fixableWarningCount: result.fixableWarningCount,
|
|
173
|
+
warningCount: result.warningCount,
|
|
174
|
+
messages: result.messages,
|
|
175
|
+
raw: result,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
totalErrorCount,
|
|
180
|
+
totalFatalErrorCount,
|
|
181
|
+
totalFixableErrorCount,
|
|
182
|
+
totalFixableWarningCount,
|
|
183
|
+
totalWarningCount,
|
|
184
|
+
componentsResults,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private computeManyComponentsTotals(componentsResults: ComponentLintResult[]) {
|
|
189
|
+
let totalErrorCount = 0;
|
|
190
|
+
let totalFatalErrorCount = 0;
|
|
191
|
+
let totalFixableErrorCount = 0;
|
|
192
|
+
let totalFixableWarningCount = 0;
|
|
193
|
+
let totalWarningCount = 0;
|
|
194
|
+
let totalComponentsWithErrorCount = 0;
|
|
195
|
+
let totalComponentsWithFatalErrorCount = 0;
|
|
196
|
+
let totalComponentsWithFixableErrorCount = 0;
|
|
197
|
+
let totalComponentsWithFixableWarningCount = 0;
|
|
198
|
+
let totalComponentsWithWarningCount = 0;
|
|
199
|
+
|
|
200
|
+
componentsResults.forEach((result) => {
|
|
201
|
+
if (result.totalErrorCount) {
|
|
202
|
+
totalErrorCount += result.totalErrorCount;
|
|
203
|
+
totalComponentsWithErrorCount += 1;
|
|
204
|
+
}
|
|
205
|
+
// @ts-ignore - missing from the @types/eslint lib
|
|
206
|
+
if (result.totalFatalErrorCount) {
|
|
207
|
+
totalFatalErrorCount += result.totalFatalErrorCount;
|
|
208
|
+
totalComponentsWithFatalErrorCount += 1;
|
|
209
|
+
}
|
|
210
|
+
if (result.totalFixableErrorCount) {
|
|
211
|
+
totalFixableErrorCount += result.totalFixableErrorCount;
|
|
212
|
+
totalComponentsWithFixableErrorCount += 1;
|
|
213
|
+
}
|
|
214
|
+
if (result.totalFixableWarningCount) {
|
|
215
|
+
totalFixableWarningCount += result.totalFixableWarningCount;
|
|
216
|
+
totalComponentsWithFixableWarningCount += 1;
|
|
217
|
+
}
|
|
218
|
+
if (result.totalWarningCount) {
|
|
219
|
+
totalWarningCount += result.totalWarningCount;
|
|
220
|
+
totalComponentsWithWarningCount += 1;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
totalErrorCount,
|
|
225
|
+
totalFatalErrorCount,
|
|
226
|
+
totalFixableErrorCount,
|
|
227
|
+
totalFixableWarningCount,
|
|
228
|
+
totalWarningCount,
|
|
229
|
+
componentsResults,
|
|
230
|
+
totalComponentsWithErrorCount,
|
|
231
|
+
totalComponentsWithFatalErrorCount,
|
|
232
|
+
totalComponentsWithFixableErrorCount,
|
|
233
|
+
totalComponentsWithFixableWarningCount,
|
|
234
|
+
totalComponentsWithWarningCount,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Create the eslint instance by options that was already merged with context
|
|
240
|
+
* @param options
|
|
241
|
+
* @param ESLintModule
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
private createEslint(options: ESLintLib.Options, ESLintModule?: any): ESLintLib {
|
|
245
|
+
// eslint-disable-next-line no-new
|
|
246
|
+
if (ESLintModule) new ESLintModule.ESLint(options);
|
|
247
|
+
return new ESLintLib(options);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
version() {
|
|
251
|
+
if (this.ESLint) return this.ESLint.version;
|
|
252
|
+
return ESLintLib.version;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function getCacheDir(rootDir): string {
|
|
257
|
+
return path.join(rootDir, 'node_modules', '.cache');
|
|
258
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { MainRuntime } from '@teambit/cli';
|
|
2
|
+
// import { Linter as ESLinter, ESLint as ESLintLib } from 'eslint';
|
|
3
|
+
import { ESLint as ESLintLib } from 'eslint';
|
|
4
|
+
import { Linter, LinterContext, LinterMain } from '@teambit/linter';
|
|
5
|
+
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
6
|
+
import { EslintConfigMutator } from '@teambit/defender.eslint.config-mutator';
|
|
7
|
+
import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
|
|
8
|
+
import { ESLintAspect } from './eslint.aspect';
|
|
9
|
+
import { ESLintLinter } from './eslint.linter';
|
|
10
|
+
|
|
11
|
+
export type ESLintOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* linter config for eslint.
|
|
14
|
+
*/
|
|
15
|
+
// config: ESLinter.Config;
|
|
16
|
+
config: ESLintLib.Options;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* specify to path to resolve eslint plugins from.
|
|
20
|
+
*/
|
|
21
|
+
pluginPath?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* decide the formatter for the CLI output.
|
|
25
|
+
*/
|
|
26
|
+
formatter?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* file types to lint.
|
|
30
|
+
*/
|
|
31
|
+
extensions?: string[];
|
|
32
|
+
|
|
33
|
+
// TODO: improve type
|
|
34
|
+
/**
|
|
35
|
+
* typescript config for eslint.
|
|
36
|
+
* If you pass this, bit will auto generate a temp config file in `node_modules/.cache` and pass it to eslint.
|
|
37
|
+
* In case you have include/exclude props in the tsconfig, they will be changed to handle the fact that they are inside the node_modules/.cache folder.
|
|
38
|
+
* a `../../` will be added to the beginning of the path.
|
|
39
|
+
*/
|
|
40
|
+
tsConfig?: Record<string, any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type EslintConfigTransformContext = {
|
|
44
|
+
fix: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type EslintConfigTransformer = (
|
|
48
|
+
config: EslintConfigMutator,
|
|
49
|
+
context: EslintConfigTransformContext
|
|
50
|
+
) => EslintConfigMutator;
|
|
51
|
+
|
|
52
|
+
export class ESLintMain {
|
|
53
|
+
constructor(private logger: Logger) {}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* create a eslint linter instance.
|
|
57
|
+
* @param options eslint options.
|
|
58
|
+
* @param ESLintModule reference to an `eslint` module.
|
|
59
|
+
*/
|
|
60
|
+
createLinter(
|
|
61
|
+
context: LinterContext,
|
|
62
|
+
options: ESLintOptions,
|
|
63
|
+
transformers: EslintConfigTransformer[] = [],
|
|
64
|
+
ESLintModule?: any
|
|
65
|
+
): Linter {
|
|
66
|
+
const mergedOptions = getOptions(options, context);
|
|
67
|
+
const configMutator = new EslintConfigMutator(mergedOptions);
|
|
68
|
+
const transformerContext: EslintConfigTransformContext = { fix: !!context.fix };
|
|
69
|
+
const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
|
|
70
|
+
|
|
71
|
+
return new ESLintLinter(this.logger, afterMutation.raw, ESLintModule);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static runtime = MainRuntime;
|
|
75
|
+
|
|
76
|
+
static dependencies = [LoggerAspect];
|
|
77
|
+
|
|
78
|
+
static async provider([loggerExt]: [LoggerMain, WorkspaceConfigFilesMain, LinterMain]): Promise<ESLintMain> {
|
|
79
|
+
const logger = loggerExt.createLogger(ESLintAspect.id);
|
|
80
|
+
return new ESLintMain(logger);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ESLintAspect.addRuntime(ESLintMain);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* get options for eslint.
|
|
88
|
+
*/
|
|
89
|
+
function getOptions(options: ESLintOptions, context: LinterContext): ESLintOptions {
|
|
90
|
+
const mergedConfig: ESLintLib.Options = {
|
|
91
|
+
// @ts-ignore - this is a bug in the @types/eslint types
|
|
92
|
+
overrideConfig: options.config,
|
|
93
|
+
extensions: context.extensionFormats,
|
|
94
|
+
useEslintrc: false,
|
|
95
|
+
cwd: options.pluginPath,
|
|
96
|
+
fix: !!context.fix,
|
|
97
|
+
fixTypes: context.fixTypes,
|
|
98
|
+
};
|
|
99
|
+
return Object.assign({}, options, { config: mergedConfig, extensions: context.extensionFormats });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function runTransformersWithContext(
|
|
103
|
+
config: EslintConfigMutator,
|
|
104
|
+
transformers: EslintConfigTransformer[] = [],
|
|
105
|
+
context: EslintConfigTransformContext
|
|
106
|
+
): EslintConfigMutator {
|
|
107
|
+
if (!Array.isArray(transformers)) return config;
|
|
108
|
+
const newConfig = transformers.reduce((acc, transformer) => {
|
|
109
|
+
return transformer(acc, context);
|
|
110
|
+
}, config);
|
|
111
|
+
return newConfig;
|
|
112
|
+
}
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/eslint",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/defender/eslint",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.defender",
|
|
8
8
|
"name": "eslint",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eslint": "7.32.0",
|
|
@@ -15,29 +15,26 @@
|
|
|
15
15
|
"object-hash": "2.1.1",
|
|
16
16
|
"p-map-series": "2.1.0",
|
|
17
17
|
"@babel/runtime": "7.23.2",
|
|
18
|
-
"core-js": "^3.0.0",
|
|
19
18
|
"@teambit/harmony": "0.4.6",
|
|
20
|
-
"@teambit/component": "1.0.
|
|
21
|
-
"@teambit/linter": "1.0.
|
|
22
|
-
"@teambit/logger": "0.0.
|
|
23
|
-
"@teambit/cli": "0.0.
|
|
19
|
+
"@teambit/component": "1.0.108",
|
|
20
|
+
"@teambit/linter": "1.0.108",
|
|
21
|
+
"@teambit/logger": "0.0.933",
|
|
22
|
+
"@teambit/cli": "0.0.840",
|
|
24
23
|
"@teambit/defender.eslint.config-mutator": "0.0.96",
|
|
25
|
-
"@teambit/workspace-config-files": "1.0.
|
|
24
|
+
"@teambit/workspace-config-files": "1.0.108"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"@types/react": "^17.0.8",
|
|
29
27
|
"@types/eslint": "7.28.0",
|
|
30
28
|
"@types/fs-extra": "9.0.7",
|
|
31
29
|
"@types/lodash": "4.14.165",
|
|
32
30
|
"@types/object-hash": "1.3.4",
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"@
|
|
36
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
31
|
+
"@types/jest": "^29.2.2",
|
|
32
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
33
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
37
34
|
},
|
|
38
35
|
"peerDependencies": {
|
|
39
|
-
"react": "^
|
|
40
|
-
"react
|
|
36
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
37
|
+
"@types/react": "^18.2.12"
|
|
41
38
|
},
|
|
42
39
|
"license": "Apache-2.0",
|
|
43
40
|
"optionalDependencies": {},
|
|
@@ -51,7 +48,7 @@
|
|
|
51
48
|
},
|
|
52
49
|
"private": false,
|
|
53
50
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
51
|
+
"node": ">=16.0.0"
|
|
55
52
|
},
|
|
56
53
|
"repository": {
|
|
57
54
|
"type": "git",
|
|
@@ -60,12 +57,9 @@
|
|
|
60
57
|
"keywords": [
|
|
61
58
|
"bit",
|
|
62
59
|
"bit-aspect",
|
|
60
|
+
"bit-core-aspect",
|
|
63
61
|
"components",
|
|
64
62
|
"collaboration",
|
|
65
|
-
"web"
|
|
66
|
-
"react",
|
|
67
|
-
"react-components",
|
|
68
|
-
"angular",
|
|
69
|
-
"angular-components"
|
|
63
|
+
"web"
|
|
70
64
|
]
|
|
71
65
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"lib": [
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"composite": true,
|
|
8
|
+
"target": "es2020",
|
|
9
|
+
"module": "es2020",
|
|
10
|
+
"jsx": "react-jsx",
|
|
15
11
|
"declaration": true,
|
|
16
12
|
"sourceMap": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
13
|
"experimentalDecorators": true,
|
|
19
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"strictPropertyInitialization": false,
|
|
28
|
-
"strict": true,
|
|
29
|
-
"noImplicitAny": false,
|
|
30
|
-
"preserveConstEnums": true
|
|
18
|
+
"allowJs": true,
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"emitDeclarationOnly": true
|
|
31
21
|
},
|
|
32
22
|
"exclude": [
|
|
23
|
+
"artifacts",
|
|
24
|
+
"public",
|
|
33
25
|
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"package.json",
|
|
34
28
|
"esm.mjs",
|
|
35
|
-
"
|
|
29
|
+
"**/*.cjs",
|
|
30
|
+
"./dist"
|
|
36
31
|
],
|
|
37
32
|
"include": [
|
|
38
33
|
"**/*",
|
package/types/asset.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ declare module '*.png' {
|
|
|
5
5
|
declare module '*.svg' {
|
|
6
6
|
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
7
|
|
|
8
|
-
export const ReactComponent: FunctionComponent<
|
|
8
|
+
export const ReactComponent: FunctionComponent<
|
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
|
10
|
+
>;
|
|
9
11
|
const src: string;
|
|
10
12
|
export default src;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
14
|
declare module '*.jpg' {
|
|
15
15
|
const value: any;
|
|
16
16
|
export = value;
|
|
@@ -27,3 +27,15 @@ declare module '*.bmp' {
|
|
|
27
27
|
const value: any;
|
|
28
28
|
export = value;
|
|
29
29
|
}
|
|
30
|
+
declare module '*.otf' {
|
|
31
|
+
const value: any;
|
|
32
|
+
export = value;
|
|
33
|
+
}
|
|
34
|
+
declare module '*.woff' {
|
|
35
|
+
const value: any;
|
|
36
|
+
export = value;
|
|
37
|
+
}
|
|
38
|
+
declare module '*.woff2' {
|
|
39
|
+
const value: any;
|
|
40
|
+
export = value;
|
|
41
|
+
}
|