@@ -6,7 +6,8 @@ import * as isCI from 'is-ci';
6
6
import { default as ora } from 'ora' ;
7
7
import * as osLocale from 'os-locale' ;
8
8
9
- import { appInsights , configStore , debug as d , fs , logger , misc , network , npm } from '@hint/utils' ;
9
+ import { appInsights , configStore , debug as d , fs , logger , misc , network , npm , ConnectorConfig , normalizeHints , HintsConfigObject , HintSeverity } from '@hint/utils' ;
10
+ import { Problem , Severity } from '@hint/utils/dist/src/types/problems' ;
10
11
11
12
import {
12
13
AnalyzerError ,
@@ -17,11 +18,11 @@ import {
17
18
UserConfig
18
19
} from '../types' ;
19
20
import { loadHintPackage } from '../utils/packages/load-hint-package' ;
20
- import { Problem , Severity } from '@hint/utils/dist/src/types/problems' ;
21
21
22
22
import { createAnalyzer , getUserConfig } from '../' ;
23
23
import { Analyzer } from '../analyzer' ;
24
24
import { AnalyzerErrorStatus } from '../enums/error-status' ;
25
+ import { loadConfiguration } from '../utils' ;
25
26
26
27
const { getAsUris } = network ;
27
28
const { askQuestion, mergeEnvWithOptions } = misc ;
@@ -77,6 +78,63 @@ or set the flag --tracking=on|off`;
77
78
printFrame ( message ) ;
78
79
} ;
79
80
81
+ const getHintsForTelemetry = ( hints ?: HintsConfigObject | ( string | any ) [ ] ) => {
82
+ if ( ! hints ) {
83
+ return null ;
84
+ }
85
+
86
+ const normalizedHints = normalizeHints ( hints ) ;
87
+ const result = { } as HintsConfigObject ;
88
+
89
+ for ( const [ hintId , severity ] of Object . entries ( normalizedHints ) ) {
90
+ result [ hintId ] = typeof severity === 'string' ? severity : ( severity as [ HintSeverity , any ] ) [ 0 ] ;
91
+ }
92
+
93
+ return result ;
94
+ } ;
95
+
96
+ const getHintsFromConfiguration = ( configName : string , parentConfigs : string [ ] = [ ] ) => {
97
+ try {
98
+ const configuration = loadConfiguration ( configName , parentConfigs ) ;
99
+
100
+ return {
101
+ ...getHintsFromConfigurations ( configuration . extends , [ configName , ...parentConfigs ] ) , // eslint-disable-line no-use-before-define,@typescript-eslint/no-use-before-define
102
+ ...getHintsForTelemetry ( configuration . hints )
103
+ } ;
104
+ } catch ( e ) { // If the configuration doesn't exists, ignore it and returns an empty object.
105
+ return { } ;
106
+ }
107
+ } ;
108
+
109
+ const getHintsFromConfigurations = ( configurations ?: string [ ] , parentConfigs : string [ ] = [ ] ) : any => {
110
+ if ( ! configurations || configurations . length === 0 ) {
111
+ return { } ;
112
+ }
113
+
114
+ const config = configurations [ 0 ] ;
115
+
116
+ return {
117
+ ...getHintsFromConfiguration ( config , parentConfigs ) ,
118
+ ...getHintsFromConfigurations ( configurations . slice ( 1 ) , parentConfigs )
119
+ } ;
120
+ } ;
121
+
122
+ const pruneUserConfig = ( userConfig : UserConfig ) => {
123
+ return {
124
+ browserslist : userConfig . browserslist ,
125
+ connector : userConfig . connector ? ( userConfig . connector as ConnectorConfig ) . name || userConfig . connector : undefined ,
126
+ extends : userConfig . extends ,
127
+ formatters : userConfig . formatters ,
128
+ hints : {
129
+ ...getHintsFromConfigurations ( userConfig . extends ) ,
130
+ ...getHintsForTelemetry ( userConfig . hints )
131
+ } ,
132
+ hintsTimeout : userConfig . hintsTimeout ,
133
+ language : userConfig . language ,
134
+ parsers : userConfig . parsers
135
+ } ;
136
+ } ;
137
+
80
138
/** Ask user if he wants to activate the telemetry or not. */
81
139
const askForTelemetryConfirmation = async ( userConfig : UserConfig ) => {
82
140
if ( appInsights . isConfigured ( ) ) {
@@ -111,7 +169,7 @@ const askForTelemetryConfirmation = async (userConfig: UserConfig) => {
111
169
appInsights . enable ( ) ;
112
170
113
171
appInsights . trackEvent ( 'SecondRun' ) ;
114
- appInsights . trackEvent ( 'analyze' , userConfig ) ;
172
+ appInsights . trackEvent ( 'analyze' , pruneUserConfig ( userConfig ) ) ;
115
173
116
174
return ;
117
175
}
@@ -332,7 +390,7 @@ export default async (actions: CLIOptions): Promise<boolean> => {
332
390
return false ;
333
391
}
334
392
335
- appInsights . trackEvent ( 'analyze' , userConfig ! ) ;
393
+ appInsights . trackEvent ( 'analyze' , pruneUserConfig ( userConfig ) ) ;
336
394
337
395
const start = Date . now ( ) ;
338
396
let exitCode = 0 ;
@@ -369,6 +427,7 @@ export default async (actions: CLIOptions): Promise<boolean> => {
369
427
updateCallback : undefined
370
428
} ;
371
429
430
+ /* istanbul ignore else */
372
431
if ( ! actions . debug ) {
373
432
analyzerOptions . updateCallback = ( update ) => {
374
433
spinner . text = update . message ;
0 commit comments