@teambit/linter 1.0.108 → 1.0.109
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/artifacts/preview/teambit_defender_linter-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +10 -10
- package/index.ts +0 -9
- package/lint.cmd.ts +0 -217
- package/lint.task.ts +0 -54
- package/linter-context.ts +0 -35
- package/linter-env-type.ts +0 -9
- package/linter.aspect.ts +0 -5
- package/linter.graphql.ts +0 -8
- package/linter.main.runtime.ts +0 -69
- package/linter.ts +0 -156
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["teambit.defender/linter-preview"]=n():e["teambit.defender/linter-preview"]=n()}(self,(()=>(()=>{"use strict";var e={33802:(e,n,t)=>{var o={id:"teambit.defender/linter@1.0.109",homepage:"https://bit.cloud/teambit/defender/linter",exported:!0};function r(){const e=i(t(87363));return r=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,r.__bit_component=o,i.__bit_component=o;const a=()=>r().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},r().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/linter.svg"}));a.__bit_component=o,n.Logo=a},54272:(e,n,t)=>{Object.defineProperty(n,"ZP",{enumerable:!0,get:function(){return o.default}});var o=r(t(43538));function r(e){return e&&e.__esModule?e:{default:e}}r.__bit_component={id:"teambit.defender/content/linter-overview@1.95.0",homepage:"https://bit.dev/teambit/defender/content/linter-overview",exported:!0}},43538:(e,n,t)=>{var o={id:"teambit.defender/content/linter-overview@1.95.0",homepage:"https://bit.dev/teambit/defender/content/linter-overview",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=c,p(t(87363));var r=t(40040),i=t(70500),a=["components"];function p(e){return e&&e.__esModule?e:{default:e}}function d(){return d=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},d.apply(this,arguments)}function l(e,n){if(null==e)return{};var t,o,r=s(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)t=i[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}function s(e,n){if(null==e)return{};var t,o,r={},i=Object.keys(e);for(o=0;o<i.length;o++)t=i[o],n.indexOf(t)>=0||(r[t]=e[t]);return r}p.__bit_component=o,d.__bit_component=o,l.__bit_component=o,s.__bit_component=o;var m={},u="wrapper";function c(e){var n=e.components,t=l(e,a);return(0,r.mdx)(u,d({},m,t,{components:n,mdxType:"MDXLayout"}),(0,r.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,r.mdx)("h1",null,"Overview"),(0,r.mdx)("p",null,"Linting helps us maintain consistent code styling and avoid potential bugs by analyzing our source code, statically, before it is compiled and executed."),(0,r.mdx)("p",null,"The Linter aspect simplifies and standardizes the process of component linting. It does so for linting during development (in the workspace) and for linting during component build (in a capsule, as part of the ",(0,r.mdx)("a",{parentName:"p",href:"/builder/build-pipelines"},"Build Pipeline"),")"),(0,r.mdx)("h2",null,"Linting in development"),(0,r.mdx)("p",null,"Bit lints all components in the ",(0,r.mdx)("a",{parentName:"p",href:"/workspace/overview"},"Workspace")," using just a single command. That is true for components of all types, regardless of their specific ",(0,r.mdx)("a",{parentName:"p",href:"/envs/overview"},"Env"),", and as a consequence of that, their specific Linter implementation"," and configuration."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-bash"},"bit lint\n")),(0,r.mdx)("p",null,"To learn more on linting during development, please refer to ",(0,r.mdx)("a",{parentName:"p",href:"/linter/workspace-linting"},"Workspace Linting"),"."),(0,r.mdx)("h2",null,"Linting during build"),(0,r.mdx)("p",null,"During build, the lint task is only used for checking linting issues. it will not re-write the components with the auto fix option."),(0,r.mdx)("p",null,"Testing components for distribution is done during ",(0,r.mdx)("inlineCode",{parentName:"p"},"build")," by the Bit ",(0,r.mdx)("a",{parentName:"p",href:"/builder/overview"},"Builder"),"."),(0,r.mdx)("p",null,"Component build can be simulated with ",(0,r.mdx)("inlineCode",{parentName:"p"},"bit build")," and done through ",(0,r.mdx)("a",{parentName:"p",href:"/components/tags"},"Tag")," or ",(0,r.mdx)("a",{parentName:"p",href:"/components/snaps"},"Snap")),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-bash"},"bit build\n")),(0,r.mdx)("p",null,"By default, linting is ",(0,r.mdx)("strong",{parentName:"p"},"not")," part of the ",(0,r.mdx)("a",{parentName:"p",href:"/builder/build-pipelines"},"Build Pipeline"),"."),(0,r.mdx)("h2",null,"Configuring and implementing Linters"),(0,r.mdx)("p",null,"The Linter implementation"," is configured in the ",(0,r.mdx)("a",{parentName:"p",href:"/envs/overview"},"Env")," which is configured on your ",(0,r.mdx)("a",{parentName:"p",href:"/components/overview"},"Component"),". Customizing it can be done by ",(0,r.mdx)("a",{parentName:"p",href:"/"},"customizing an existing env with your linter")," or by ",(0,r.mdx)("a",{parentName:"p",href:"/envs/customizing-env"},"implementing your own Env"),"."),(0,r.mdx)("p",null,"Linter can also be implemented into Bit through few interfaces. ")))}c.__bit_component=o,c.isMDXComponent=!0},40040:e=>{e.exports=MdxJsReact},87363:e=>{e.exports=React},70500:e=>{e.exports=TeambitMdxUiMdxScopeContext}},n={};function t(o){var r=n[o];if(void 0!==r)return r.exports;var i=n[o]={exports:{}};return e[o](i,i.exports,t),i.exports}t.d=(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},t.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{t.r(o),t.d(o,{compositions:()=>u,compositions_metadata:()=>f,overview:()=>c});var e={};t.r(e),t.d(e,{default:()=>m});var n=t(33802),r=(t(87363),t(40040)),i=t(70500),a=t(54272),p=["components"];function d(){return d=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},d.apply(this,arguments)}var l={},s="wrapper";function m(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,o,r=function(e,n){if(null==e)return{};var t,o,r={},i=Object.keys(e);for(o=0;o<i.length;o++)t=i[o],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)t=i[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}(e,p);return(0,r.mdx)(s,d({},l,t,{components:n,mdxType:"MDXLayout"}),(0,r.mdx)(i.MDXScopeProvider,{components:{LinterOverview:a.ZP},mdxType:"MDXScopeProvider"},(0,r.mdx)(a.ZP,{mdxType:"LinterOverview"})))}m.isMDXComponent=!0;const u=[n],c=[e],f={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),o})()));
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_linter@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_linter@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_linter@1.0.109/dist/linter.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_linter@1.0.109/dist/linter.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/linter",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.109",
|
4
4
|
"homepage": "https://bit.cloud/teambit/defender/linter",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.defender",
|
8
8
|
"name": "linter",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.109"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "2.4.2",
|
@@ -15,13 +15,13 @@
|
|
15
15
|
"cli-highlight": "2.1.9",
|
16
16
|
"ink": "3.2.0",
|
17
17
|
"@teambit/harmony": "0.4.6",
|
18
|
-
"@teambit/cli": "0.0.
|
19
|
-
"@teambit/component": "1.0.
|
20
|
-
"@teambit/envs": "1.0.
|
21
|
-
"@teambit/workspace": "1.0.
|
22
|
-
"@teambit/builder": "1.0.
|
23
|
-
"@teambit/isolator": "1.0.
|
24
|
-
"@teambit/logger": "0.0.
|
18
|
+
"@teambit/cli": "0.0.841",
|
19
|
+
"@teambit/component": "1.0.109",
|
20
|
+
"@teambit/envs": "1.0.109",
|
21
|
+
"@teambit/workspace": "1.0.109",
|
22
|
+
"@teambit/builder": "1.0.109",
|
23
|
+
"@teambit/isolator": "1.0.109",
|
24
|
+
"@teambit/logger": "0.0.934"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"@types/lodash": "4.14.165",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"@types/jest": "^29.2.2",
|
30
30
|
"@types/testing-library__jest-dom": "^5.9.5",
|
31
31
|
"@teambit/defender.content.linter-overview": "1.95.0",
|
32
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
32
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14"
|
33
33
|
},
|
34
34
|
"peerDependencies": {
|
35
35
|
"react": "^17.0.0 || ^18.0.0",
|
package/index.ts
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
import { LinterAspect } from './linter.aspect';
|
2
|
-
|
3
|
-
export { LinterAspect };
|
4
|
-
export type { LinterMain, LinterConfig } from './linter.main.runtime';
|
5
|
-
export type { LintResults, Linter, LintResult, ComponentLintResult } from './linter';
|
6
|
-
export type { LintTask } from './lint.task';
|
7
|
-
export type { LinterContext, LinterOptions } from './linter-context';
|
8
|
-
export type { LinterEnv } from './linter-env-type';
|
9
|
-
export default LinterAspect;
|
package/lint.cmd.ts
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
import { TimerResponse, Timer } from '@teambit/legacy/dist/toolbox/timer';
|
2
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
3
|
-
import { ComponentFactory, ComponentID } from '@teambit/component';
|
4
|
-
import chalk from 'chalk';
|
5
|
-
import { EnvsExecutionResult } from '@teambit/envs';
|
6
|
-
import { Workspace } from '@teambit/workspace';
|
7
|
-
import { compact, flatten, omit } from 'lodash';
|
8
|
-
import { LinterMain } from './linter.main.runtime';
|
9
|
-
import { ComponentLintResult, LintResults } from './linter';
|
10
|
-
import { FixTypes, LinterOptions } from './linter-context';
|
11
|
-
|
12
|
-
export type LintCmdOptions = {
|
13
|
-
changed?: boolean;
|
14
|
-
fix?: boolean;
|
15
|
-
fixType?: string;
|
16
|
-
json?: boolean;
|
17
|
-
};
|
18
|
-
|
19
|
-
/**
|
20
|
-
* A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component
|
21
|
-
*/
|
22
|
-
export type JsonComponentLintResult = Omit<ComponentLintResult, 'component'> & {
|
23
|
-
componentId: ComponentID;
|
24
|
-
};
|
25
|
-
|
26
|
-
export type JsonLintDataResults = Omit<LintResults, 'results'> & { results: JsonComponentLintResult[] };
|
27
|
-
/**
|
28
|
-
* A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component
|
29
|
-
*/
|
30
|
-
export type JsonLintResultsData = {
|
31
|
-
duration: TimerResponse;
|
32
|
-
lintResults: JsonLintDataResults;
|
33
|
-
componentsIdsToLint: string[];
|
34
|
-
};
|
35
|
-
|
36
|
-
export type JsonLintResults = {
|
37
|
-
code: number;
|
38
|
-
data: JsonLintResultsData;
|
39
|
-
};
|
40
|
-
|
41
|
-
export class LintCmd implements Command {
|
42
|
-
name = 'lint [component...]';
|
43
|
-
description = 'lint components in the development workspace';
|
44
|
-
helpUrl = 'reference/linting/linter-overview';
|
45
|
-
group = 'development';
|
46
|
-
options = [
|
47
|
-
['c', 'changed', 'lint only new and modified components'],
|
48
|
-
['f', 'fix', 'automatically fix problems'],
|
49
|
-
['', 'fix-type <fixType>', 'specify the types of fixes to apply (problem, suggestion, layout)'],
|
50
|
-
['j', 'json', 'return the lint results in json format'],
|
51
|
-
] as CommandOptions;
|
52
|
-
|
53
|
-
constructor(private linter: LinterMain, private componentHost: ComponentFactory, private workspace: Workspace) {}
|
54
|
-
|
55
|
-
async report([components = []]: [string[]], linterOptions: LintCmdOptions) {
|
56
|
-
const { code, data } = await this.json([components], linterOptions);
|
57
|
-
const { lintResults, componentsIdsToLint } = data;
|
58
|
-
const title = chalk.bold(
|
59
|
-
`linting total of ${chalk.cyan(componentsIdsToLint.length.toString())} component(s) in workspace '${chalk.cyan(
|
60
|
-
this.componentHost.name
|
61
|
-
)}'`
|
62
|
-
);
|
63
|
-
|
64
|
-
const componentsOutputs = lintResults.results
|
65
|
-
.map((lintRes) => {
|
66
|
-
const compTitle = chalk.bold.cyan(lintRes.componentId.toString({ ignoreVersion: true }));
|
67
|
-
const compOutput = lintRes.output;
|
68
|
-
return `${compTitle}\n${compOutput}`;
|
69
|
-
})
|
70
|
-
.join('\n');
|
71
|
-
|
72
|
-
const summary = this.getSummarySection(data);
|
73
|
-
return { code, data: `${title}\n\n${componentsOutputs}\n\n${summary}` };
|
74
|
-
}
|
75
|
-
|
76
|
-
private getSummarySection(data: JsonLintResultsData) {
|
77
|
-
const { duration, lintResults, componentsIdsToLint } = data;
|
78
|
-
const { seconds } = duration;
|
79
|
-
const summaryTitle = `linted ${chalk.cyan(componentsIdsToLint.length.toString())} components in ${chalk.cyan(
|
80
|
-
seconds.toString()
|
81
|
-
)} seconds`;
|
82
|
-
|
83
|
-
const totalFieldsMap = [
|
84
|
-
{ itemsDataField: 'totalErrorCount', componentsDataField: 'totalComponentsWithErrorCount', label: 'Errors' },
|
85
|
-
{
|
86
|
-
itemsDataField: 'totalFatalErrorCount',
|
87
|
-
componentsDataField: 'totalComponentsWithFatalErrorCount',
|
88
|
-
label: 'FatalErrors',
|
89
|
-
},
|
90
|
-
{
|
91
|
-
itemsDataField: 'totalFixableErrorCount',
|
92
|
-
componentsDataField: 'totalComponentsWithFixableErrorCount',
|
93
|
-
label: 'FixableErrors',
|
94
|
-
},
|
95
|
-
{
|
96
|
-
itemsDataField: 'totalFixableWarningCount',
|
97
|
-
componentsDataField: 'totalComponentsWithFixableWarningCount',
|
98
|
-
label: 'FixableWarnings',
|
99
|
-
},
|
100
|
-
{
|
101
|
-
itemsDataField: 'totalWarningCount',
|
102
|
-
componentsDataField: 'totalComponentsWithWarningCount',
|
103
|
-
label: 'Warnings',
|
104
|
-
},
|
105
|
-
];
|
106
|
-
|
107
|
-
const summaryTotals = totalFieldsMap
|
108
|
-
.map((item) =>
|
109
|
-
this.renderTotalLine(lintResults[item.componentsDataField], lintResults[item.itemsDataField], item.label)
|
110
|
-
)
|
111
|
-
.filter(Boolean)
|
112
|
-
.join('\n');
|
113
|
-
const summary = `${summaryTitle}\n${summaryTotals}`;
|
114
|
-
return summary;
|
115
|
-
}
|
116
|
-
|
117
|
-
private renderTotalLine(componentsCount: number, itemsCount: number, fieldLabel: string): string | undefined {
|
118
|
-
if (itemsCount === 0) return undefined;
|
119
|
-
return `total of ${chalk.green(itemsCount.toString())} ${chalk.cyan(fieldLabel)} (from ${chalk.green(
|
120
|
-
componentsCount.toString()
|
121
|
-
)} components)`;
|
122
|
-
}
|
123
|
-
|
124
|
-
async json([components = []]: [string[]], linterOptions: LintCmdOptions): Promise<JsonLintResults> {
|
125
|
-
const timer = Timer.create();
|
126
|
-
timer.start();
|
127
|
-
const componentsIds = await this.getIdsToLint(components, linterOptions.changed);
|
128
|
-
const componentsToLint = await this.workspace.getMany(componentsIds);
|
129
|
-
const opts: LinterOptions = {
|
130
|
-
fix: linterOptions.fix,
|
131
|
-
fixTypes: linterOptions.fixType ? (linterOptions.fixType.split(',') as FixTypes) : undefined,
|
132
|
-
};
|
133
|
-
const linterResults = await this.linter.lint(componentsToLint, opts);
|
134
|
-
const jsonLinterResults = toJsonLintResults(linterResults);
|
135
|
-
const timerResponse = timer.stop();
|
136
|
-
let code = 0;
|
137
|
-
if (jsonLinterResults.totalErrorCount || jsonLinterResults.totalFatalErrorCount) {
|
138
|
-
code = 1;
|
139
|
-
}
|
140
|
-
return {
|
141
|
-
code,
|
142
|
-
data: {
|
143
|
-
duration: timerResponse,
|
144
|
-
lintResults: jsonLinterResults,
|
145
|
-
componentsIdsToLint: componentsToLint.map((comp) => comp.id.toString()),
|
146
|
-
},
|
147
|
-
};
|
148
|
-
}
|
149
|
-
|
150
|
-
private async getIdsToLint(components: string[], changed = false): Promise<ComponentID[]> {
|
151
|
-
if (components.length) {
|
152
|
-
return this.workspace.resolveMultipleComponentIds(components);
|
153
|
-
}
|
154
|
-
if (changed) {
|
155
|
-
return this.workspace.getNewAndModifiedIds();
|
156
|
-
}
|
157
|
-
return this.componentHost.listIds();
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
function toJsonLintResults(results: EnvsExecutionResult<LintResults>): JsonLintDataResults {
|
162
|
-
let totalErrorCount = 0;
|
163
|
-
let totalFatalErrorCount = 0;
|
164
|
-
let totalFixableErrorCount = 0;
|
165
|
-
let totalFixableWarningCount = 0;
|
166
|
-
let totalWarningCount = 0;
|
167
|
-
let totalComponentsWithErrorCount = 0;
|
168
|
-
let totalComponentsWithFatalErrorCount = 0;
|
169
|
-
let totalComponentsWithFixableErrorCount = 0;
|
170
|
-
let totalComponentsWithFixableWarningCount = 0;
|
171
|
-
let totalComponentsWithWarningCount = 0;
|
172
|
-
|
173
|
-
const newResults = results.results.map((res) => {
|
174
|
-
const resultsWithoutComponent = res.data?.results.map((result) => {
|
175
|
-
return Object.assign({}, { componentId: result.component.id }, omit(result, ['component']));
|
176
|
-
});
|
177
|
-
|
178
|
-
if (res.data) {
|
179
|
-
if (res.data.totalErrorCount) {
|
180
|
-
totalErrorCount += res.data.totalErrorCount;
|
181
|
-
totalComponentsWithErrorCount += res.data.totalComponentsWithErrorCount ?? 0;
|
182
|
-
}
|
183
|
-
if (res.data.totalFatalErrorCount) {
|
184
|
-
totalFatalErrorCount += res.data.totalFatalErrorCount;
|
185
|
-
totalComponentsWithFatalErrorCount += res.data.totalComponentsWithFatalErrorCount ?? 0;
|
186
|
-
}
|
187
|
-
if (res.data.totalFixableErrorCount) {
|
188
|
-
totalFixableErrorCount += res.data.totalFixableErrorCount;
|
189
|
-
totalComponentsWithFixableErrorCount += res.data.totalComponentsWithFixableErrorCount ?? 0;
|
190
|
-
}
|
191
|
-
if (res.data.totalFixableWarningCount) {
|
192
|
-
totalFixableWarningCount += res.data.totalFixableWarningCount;
|
193
|
-
totalComponentsWithFixableWarningCount += res.data.totalComponentsWithFixableWarningCount ?? 0;
|
194
|
-
}
|
195
|
-
if (res.data.totalWarningCount) {
|
196
|
-
totalWarningCount += res.data.totalWarningCount;
|
197
|
-
totalComponentsWithWarningCount += res.data.totalComponentsWithWarningCount ?? 0;
|
198
|
-
}
|
199
|
-
}
|
200
|
-
|
201
|
-
return compact(resultsWithoutComponent);
|
202
|
-
});
|
203
|
-
return {
|
204
|
-
results: compact(flatten(newResults)),
|
205
|
-
totalErrorCount,
|
206
|
-
totalFatalErrorCount,
|
207
|
-
totalFixableErrorCount,
|
208
|
-
totalFixableWarningCount,
|
209
|
-
totalWarningCount,
|
210
|
-
totalComponentsWithErrorCount,
|
211
|
-
totalComponentsWithFatalErrorCount,
|
212
|
-
totalComponentsWithFixableErrorCount,
|
213
|
-
totalComponentsWithFixableWarningCount,
|
214
|
-
totalComponentsWithWarningCount,
|
215
|
-
errors: results?.errors,
|
216
|
-
};
|
217
|
-
}
|
package/lint.task.ts
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { BuildTask, BuiltTaskResult, BuildContext, ComponentResult } from '@teambit/builder';
|
3
|
-
import { Component, ComponentMap } from '@teambit/component';
|
4
|
-
import { CapsuleList } from '@teambit/isolator';
|
5
|
-
import { Linter } from './linter';
|
6
|
-
import { LinterContext } from './linter-context';
|
7
|
-
|
8
|
-
export class LintTask implements BuildTask {
|
9
|
-
constructor(readonly aspectId: string, readonly name = 'lint') {}
|
10
|
-
|
11
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
12
|
-
const linter: Linter = context.env.getLinter();
|
13
|
-
const rootDir = context.capsuleNetwork.capsulesRootDir;
|
14
|
-
const componentsDirMap = this.getComponentsDirectory(
|
15
|
-
rootDir,
|
16
|
-
context.components,
|
17
|
-
context.capsuleNetwork.graphCapsules
|
18
|
-
);
|
19
|
-
|
20
|
-
// @ts-ignore TODO: fix this
|
21
|
-
const linterContext: LinterContext = {
|
22
|
-
rootDir,
|
23
|
-
componentsDirMap,
|
24
|
-
...context,
|
25
|
-
};
|
26
|
-
const results = await linter.lint(linterContext);
|
27
|
-
const componentsResults = results.results.map((lintResult): ComponentResult => {
|
28
|
-
return {
|
29
|
-
component: lintResult.component,
|
30
|
-
metadata: {
|
31
|
-
output: lintResult.output,
|
32
|
-
results: lintResult.results,
|
33
|
-
},
|
34
|
-
errors: [],
|
35
|
-
};
|
36
|
-
});
|
37
|
-
|
38
|
-
return {
|
39
|
-
componentsResults,
|
40
|
-
};
|
41
|
-
}
|
42
|
-
|
43
|
-
private getComponentsDirectory(
|
44
|
-
capsuleRootDir: string,
|
45
|
-
components: Component[],
|
46
|
-
capsuleList: CapsuleList
|
47
|
-
): ComponentMap<string> {
|
48
|
-
return ComponentMap.as<string>(components, (component) => {
|
49
|
-
const fullPath = capsuleList.getCapsule(component.id)?.path || '';
|
50
|
-
const relativePath = path.relative(capsuleRootDir, fullPath);
|
51
|
-
return relativePath;
|
52
|
-
});
|
53
|
-
}
|
54
|
-
}
|
package/linter-context.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import { ComponentMap } from '@teambit/component';
|
2
|
-
import { ExecutionContext } from '@teambit/envs';
|
3
|
-
|
4
|
-
export type FixType = 'problem' | 'suggestion' | 'layout';
|
5
|
-
export type FixTypes = Array<FixType>;
|
6
|
-
|
7
|
-
export interface LinterOptions {
|
8
|
-
/**
|
9
|
-
* extensions formats to lint. (e.g. .ts, .tsx, etc.)
|
10
|
-
*/
|
11
|
-
extensionFormats?: string[];
|
12
|
-
|
13
|
-
/**
|
14
|
-
* automatically fix problems
|
15
|
-
*/
|
16
|
-
fix?: boolean;
|
17
|
-
|
18
|
-
/**
|
19
|
-
* specify the types of fixes to apply (problem, suggestion, layout)
|
20
|
-
*/
|
21
|
-
fixTypes?: FixTypes;
|
22
|
-
}
|
23
|
-
export interface LinterContext extends ExecutionContext, LinterOptions {
|
24
|
-
quiet?: boolean;
|
25
|
-
/**
|
26
|
-
* Root dir that contains all the components in the fs that are about to be linted
|
27
|
-
* Usually it's the workspace root dir or the capsule root dir
|
28
|
-
*/
|
29
|
-
rootDir?: string;
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Component map with the path to the component in the fs
|
33
|
-
*/
|
34
|
-
componentsDirMap: ComponentMap<string>;
|
35
|
-
}
|
package/linter-env-type.ts
DELETED
package/linter.aspect.ts
DELETED
package/linter.graphql.ts
DELETED
package/linter.main.runtime.ts
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
2
|
-
import { Component, ComponentAspect, ComponentMain } from '@teambit/component';
|
3
|
-
import { EnvsAspect, EnvsMain, ExecutionContext } from '@teambit/envs';
|
4
|
-
import { LoggerAspect, LoggerMain } from '@teambit/logger';
|
5
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
6
|
-
import { LinterAspect } from './linter.aspect';
|
7
|
-
import { LinterService } from './linter.service';
|
8
|
-
import { LintTask } from './lint.task';
|
9
|
-
import { LintCmd } from './lint.cmd';
|
10
|
-
import { FixTypes, LinterOptions } from './linter-context';
|
11
|
-
import { Linter } from './linter';
|
12
|
-
|
13
|
-
export type LinterConfig = {
|
14
|
-
/**
|
15
|
-
* extension formats to lint.
|
16
|
-
*/
|
17
|
-
extensionFormats: string[];
|
18
|
-
fixTypes?: FixTypes;
|
19
|
-
};
|
20
|
-
|
21
|
-
export class LinterMain {
|
22
|
-
static runtime = MainRuntime;
|
23
|
-
|
24
|
-
constructor(private envs: EnvsMain, private linterService: LinterService) {}
|
25
|
-
|
26
|
-
/**
|
27
|
-
* lint an array of components.
|
28
|
-
*/
|
29
|
-
async lint(components: Component[], opts: LinterOptions) {
|
30
|
-
const envsRuntime = await this.envs.createEnvironment(components);
|
31
|
-
const lintResults = envsRuntime.run(this.linterService, opts);
|
32
|
-
return lintResults;
|
33
|
-
}
|
34
|
-
|
35
|
-
getLinter(context: ExecutionContext, options: LinterOptions): Linter {
|
36
|
-
return this.linterService.getLinter(context, options);
|
37
|
-
}
|
38
|
-
|
39
|
-
/**
|
40
|
-
* create a lint task for build pipelines.
|
41
|
-
* @param name name of the task.
|
42
|
-
*/
|
43
|
-
createTask(name?: string): LintTask {
|
44
|
-
return new LintTask(LinterAspect.id, name);
|
45
|
-
}
|
46
|
-
|
47
|
-
static dependencies = [EnvsAspect, CLIAspect, ComponentAspect, LoggerAspect, WorkspaceAspect];
|
48
|
-
|
49
|
-
static defaultConfig: LinterConfig = {
|
50
|
-
extensionFormats: ['.ts', '.tsx', '.js', '.jsx', '.mjs'],
|
51
|
-
fixTypes: ['layout', 'problem', 'suggestion'],
|
52
|
-
};
|
53
|
-
|
54
|
-
static async provider(
|
55
|
-
[envs, cli, component, loggerAspect, workspace]: [EnvsMain, CLIMain, ComponentMain, LoggerMain, Workspace],
|
56
|
-
config: LinterConfig
|
57
|
-
) {
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
59
|
-
const logger = loggerAspect.createLogger(LinterAspect.id);
|
60
|
-
const linterService = new LinterService(config, workspace);
|
61
|
-
const linterAspect = new LinterMain(envs, linterService);
|
62
|
-
envs.registerService(linterService);
|
63
|
-
cli.register(new LintCmd(linterAspect, component.getHost(), workspace));
|
64
|
-
|
65
|
-
return linterAspect;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
LinterAspect.addRuntime(LinterMain);
|
package/linter.ts
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
import { BuildContext } from '@teambit/builder';
|
2
|
-
import { Component } from '@teambit/component';
|
3
|
-
import { LinterContext } from './linter-context';
|
4
|
-
|
5
|
-
export type ComponentLintResult = {
|
6
|
-
/**
|
7
|
-
* the linted component.
|
8
|
-
*/
|
9
|
-
component: Component;
|
10
|
-
|
11
|
-
/**
|
12
|
-
* CLI output of the linter.
|
13
|
-
*/
|
14
|
-
output: string;
|
15
|
-
|
16
|
-
/**
|
17
|
-
* total errors count of the component (from all of the files).
|
18
|
-
*/
|
19
|
-
totalErrorCount: number;
|
20
|
-
/**
|
21
|
-
* total fatal errors count of the component (from all of the files).
|
22
|
-
*/
|
23
|
-
totalFatalErrorCount?: number;
|
24
|
-
/**
|
25
|
-
* total fixable errors count of the component (from all of the files).
|
26
|
-
*/
|
27
|
-
totalFixableErrorCount?: number;
|
28
|
-
/**
|
29
|
-
* total fatal warning count of the component (from all of the files).
|
30
|
-
*/
|
31
|
-
totalFixableWarningCount?: number;
|
32
|
-
/**
|
33
|
-
* total warning count of the component (from all of the files).
|
34
|
-
*/
|
35
|
-
totalWarningCount: number;
|
36
|
-
|
37
|
-
/**
|
38
|
-
* lint results for each one of the component files
|
39
|
-
*/
|
40
|
-
results: LintResult[];
|
41
|
-
};
|
42
|
-
|
43
|
-
export type LintResult = {
|
44
|
-
/**
|
45
|
-
* path of the linted file.
|
46
|
-
*/
|
47
|
-
filePath: string;
|
48
|
-
|
49
|
-
/**
|
50
|
-
* numbers of errors found.
|
51
|
-
*/
|
52
|
-
errorCount: number;
|
53
|
-
|
54
|
-
/**
|
55
|
-
* numbers of errors found.
|
56
|
-
*/
|
57
|
-
fatalErrorCount?: number;
|
58
|
-
|
59
|
-
/**
|
60
|
-
* numbers of fixable errors found.
|
61
|
-
*/
|
62
|
-
fixableErrorCount?: number;
|
63
|
-
|
64
|
-
/**
|
65
|
-
* numbers of fixable warning found.
|
66
|
-
*/
|
67
|
-
fixableWarningCount?: number;
|
68
|
-
|
69
|
-
/**
|
70
|
-
* number of found warnings.
|
71
|
-
*/
|
72
|
-
warningCount: number;
|
73
|
-
|
74
|
-
/**
|
75
|
-
* lint messages.
|
76
|
-
*/
|
77
|
-
messages: LintMessage[];
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Raw data as returned from the linter
|
81
|
-
*/
|
82
|
-
raw: any;
|
83
|
-
};
|
84
|
-
|
85
|
-
export type LintMessage = {
|
86
|
-
/**
|
87
|
-
* severity of the issue.
|
88
|
-
*/
|
89
|
-
severity: string;
|
90
|
-
/**
|
91
|
-
* stating column of the issue.
|
92
|
-
*/
|
93
|
-
column: number;
|
94
|
-
|
95
|
-
/**
|
96
|
-
* line of the issue.
|
97
|
-
*/
|
98
|
-
line: number;
|
99
|
-
|
100
|
-
/**
|
101
|
-
* end column of the issue.
|
102
|
-
*/
|
103
|
-
endColumn?: number;
|
104
|
-
|
105
|
-
/**
|
106
|
-
* end line of the issue.
|
107
|
-
*/
|
108
|
-
endLine?: number;
|
109
|
-
|
110
|
-
/**
|
111
|
-
* message of the issue.
|
112
|
-
*/
|
113
|
-
message: string;
|
114
|
-
|
115
|
-
/**
|
116
|
-
* lint suggestions.
|
117
|
-
*/
|
118
|
-
suggestions?: string[];
|
119
|
-
};
|
120
|
-
|
121
|
-
export type LintResults = {
|
122
|
-
results: ComponentLintResult[];
|
123
|
-
/**
|
124
|
-
* total errors count of the component (from all of the components).
|
125
|
-
*/
|
126
|
-
totalErrorCount: number;
|
127
|
-
/**
|
128
|
-
* total fatal errors count of the component (from all of the components).
|
129
|
-
*/
|
130
|
-
totalFatalErrorCount?: number;
|
131
|
-
/**
|
132
|
-
* total fixable errors count of the component (from all of the components).
|
133
|
-
*/
|
134
|
-
totalFixableErrorCount?: number;
|
135
|
-
/**
|
136
|
-
* total fatal warning count of the component (from all of the components).
|
137
|
-
*/
|
138
|
-
totalFixableWarningCount?: number;
|
139
|
-
/**
|
140
|
-
* total warning count of the component (from all of the components).
|
141
|
-
*/
|
142
|
-
totalWarningCount: number;
|
143
|
-
|
144
|
-
totalComponentsWithErrorCount: number;
|
145
|
-
totalComponentsWithFatalErrorCount?: number;
|
146
|
-
totalComponentsWithFixableErrorCount?: number;
|
147
|
-
totalComponentsWithFixableWarningCount?: number;
|
148
|
-
totalComponentsWithWarningCount: number;
|
149
|
-
|
150
|
-
errors: Error[];
|
151
|
-
};
|
152
|
-
|
153
|
-
export interface Linter {
|
154
|
-
id: string;
|
155
|
-
lint(context: LinterContext, buildContext?: BuildContext): Promise<LintResults>;
|
156
|
-
}
|