npm-groovy-lint
Advanced tools
Comparing version 5.7.0 to 5.8.0
# Changelog | ||
## [5.8.0] 2020-08-01 | ||
- Fix & enhance anonymous statistics | ||
## [5.7.0] 2020-07-23 | ||
@@ -4,0 +8,0 @@ |
const Amplitude = require("@amplitude/node"); | ||
const debug = require("debug")("npm-groovy-lint"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
const AMPLITUDE_TOKEN = "2e52ce300e4bd3a76e97e27fe1bf31ad"; | ||
let amplitudeClient; | ||
@@ -13,3 +16,3 @@ let pkgJson; | ||
if (amplitudeClient == null) { | ||
amplitudeClient = Amplitude.init("2e52ce300e4bd3a76e97e27fe1bf31ad"); | ||
amplitudeClient = Amplitude.init(AMPLITUDE_TOKEN); | ||
} | ||
@@ -91,13 +94,21 @@ if (pkgJson == null) { | ||
} | ||
// Counters | ||
if (data.summary) { | ||
if (data.summary.totalFoundNumber) { | ||
payloadFiltered.totalFoundNumber = data.summary.totalFoundNumber; | ||
// *Summary | ||
if (data.result && data.result.summary) { | ||
// Counters | ||
if (data.result.summary.totalFoundNumber) { | ||
payloadFiltered.totalFoundNumber = data.result.summary.totalFoundNumber; | ||
} | ||
if (data.options && [data.options.format, data.options.fix].includes(true) && data.summary.totalFixedNumber) { | ||
payloadFiltered.totalFixedNumber = data.summary.totalFixedNumber; | ||
if (data.options && [data.options.format, data.options.fix].includes(true) && data.result.summary.totalFixedNumber) { | ||
payloadFiltered.totalFixedNumber = data.result.summary.totalFixedNumber; | ||
} | ||
if (data.options && [data.options.format, data.options.fix].includes(true) && data.summary.totalRemainingNumber) { | ||
payloadFiltered.totalRemainingNumber = data.summary.totalRemainingNumber; | ||
if (data.options && [data.options.format, data.options.fix].includes(true) && data.result.summary.totalRemainingNumber) { | ||
payloadFiltered.totalRemainingNumber = data.result.summary.totalRemainingNumber; | ||
} | ||
// Stats of rules | ||
if (data.result.summary.detectedRules) { | ||
payloadFiltered.detectedRules = data.result.summary.detectedRules; | ||
} | ||
if (data.result.summary.fixedRules) { | ||
payloadFiltered.fixedRules = data.result.summary.fixedRules; | ||
} | ||
} | ||
@@ -124,3 +135,6 @@ return payloadFiltered; | ||
function getUuidV4() { | ||
const localStorageFileNm = "./local-storage.json"; | ||
if (globalThis.anonymousUserId) { | ||
return globalThis.anonymousUserId; | ||
} | ||
const localStorageFileNm = path.resolve(os.homedir() + "/.node-stats/local-storage.json"); | ||
const fse = require("fs-extra"); | ||
@@ -137,3 +151,10 @@ let usrLocalStorage = {}; | ||
usrLocalStorage.anonymousUserId = anonUsrId; | ||
fse.writeJsonSync(localStorageFileNm, usrLocalStorage); | ||
globalThis.anonymousUserId = usrLocalStorage.anonymousUserId; | ||
try { | ||
fse.ensureDirSync(path.resolve(os.homedir() + "/.node-stats"), { mode: "0777" }); | ||
fse.writeJsonSync(localStorageFileNm, usrLocalStorage); | ||
} catch (e) { | ||
debug(`Unable to write anonymous user id in ${localStorageFileNm} | ||
${e.message}`); | ||
} | ||
return usrLocalStorage.anonymousUserId; | ||
@@ -140,0 +161,0 @@ } |
@@ -301,3 +301,3 @@ #! /usr/bin/env node | ||
status: this.status, | ||
summary: this.lintResult.summary, | ||
result: this.lintResult, | ||
elapsed: elapsedTimeMs, | ||
@@ -304,0 +304,0 @@ options: this.options, |
@@ -21,3 +21,6 @@ // Output management | ||
totalRemainingWarningNumber: 0, | ||
totalRemainingInfoNumber: 0 | ||
totalRemainingInfoNumber: 0, | ||
detectedRules: {}, | ||
fixedRules: {} | ||
}; | ||
@@ -29,48 +32,13 @@ | ||
// Compute Error counters | ||
const fileFoundErrorsNumber = fileErrors.filter(err => { | ||
return err.severity === "error"; | ||
}).length; | ||
const fileFixedErrorsNumber = fileErrors.filter(err => { | ||
return err.severity === "error" && err.fixed && err.fixed === true; | ||
}).length; | ||
const fileRemainingErrorNumber = fileFoundErrorsNumber - fileFixedErrorsNumber; | ||
const fileErrorStats = appendErrorTypeStats("error", fileErrors, counterResultsSummary); | ||
const fileWarningStats = appendErrorTypeStats("warning", fileErrors, counterResultsSummary); | ||
const fileInfoStats = appendErrorTypeStats("info", fileErrors, counterResultsSummary); | ||
counterResultsSummary.totalFoundErrorNumber = counterResultsSummary.totalFoundErrorNumber + fileFoundErrorsNumber; | ||
counterResultsSummary.totalFixedErrorNumber = counterResultsSummary.totalFixedErrorNumber + fileFixedErrorsNumber; | ||
counterResultsSummary.totalRemainingErrorNumber = counterResultsSummary.totalRemainingErrorNumber + fileRemainingErrorNumber; | ||
// Compute Warning counters | ||
const fileFoundWarningNumber = fileErrors.filter(err => { | ||
return err.severity === "warning"; | ||
}).length; | ||
const fileFixedWarningNumber = fileErrors.filter(err => { | ||
return err.severity === "warning" && err.fixed && err.fixed === true; | ||
}).length; | ||
const fileRemainingWarningNumber = fileFoundWarningNumber - fileFixedWarningNumber; | ||
counterResultsSummary.totalFoundWarningNumber = counterResultsSummary.totalFoundWarningNumber + fileFoundWarningNumber; | ||
counterResultsSummary.totalFixedWarningNumber = counterResultsSummary.totalFixedWarningNumber + fileFixedWarningNumber; | ||
counterResultsSummary.totalRemainingWarningNumber = counterResultsSummary.totalRemainingWarningNumber + fileRemainingWarningNumber; | ||
// Compute Info counters | ||
const fileFoundInfoNumber = fileErrors.filter(err => { | ||
return err.severity === "info"; | ||
}).length; | ||
const fileFixedInfoNumber = fileErrors.filter(err => { | ||
return err.severity === "info" && err.fixed && err.fixed === true; | ||
}).length; | ||
const fileRemainingInfoNumber = fileFoundInfoNumber - fileFixedInfoNumber; | ||
counterResultsSummary.totalFoundInfoNumber = counterResultsSummary.totalFoundErrorNumber + fileFoundInfoNumber; | ||
counterResultsSummary.totalFixedInfoNumber = counterResultsSummary.totalFixedInfoNumber + fileFixedInfoNumber; | ||
counterResultsSummary.totalRemainingInfoNumber = counterResultsSummary.totalRemainingInfoNumber + fileRemainingInfoNumber; | ||
// Total ignoring severity | ||
counterResultsSummary.totalFoundNumber = | ||
counterResultsSummary.totalFoundNumber + fileFoundErrorsNumber + fileFoundWarningNumber + fileFoundInfoNumber; | ||
counterResultsSummary.totalFoundNumber + fileErrorStats.found + fileWarningStats.found + fileInfoStats.found; | ||
counterResultsSummary.totalFixedNumber = | ||
counterResultsSummary.totalFixedNumber + fileFixedErrorsNumber + fileFixedWarningNumber + fileFixedInfoNumber; | ||
counterResultsSummary.totalFixedNumber + fileErrorStats.fixed + fileWarningStats.fixed + fileInfoStats.fixed; | ||
counterResultsSummary.totalRemainingNumber = | ||
counterResultsSummary.totalRemainingNumber + fileRemainingErrorNumber + fileRemainingWarningNumber + fileRemainingInfoNumber; | ||
counterResultsSummary.totalRemainingNumber + fileErrorStats.remaining + fileWarningStats.remaining + fileInfoStats.remaining; | ||
} | ||
@@ -83,2 +51,42 @@ | ||
// Collect stats about errors in a linted / formatted / fixed file | ||
function appendErrorTypeStats(severity, fileErrors, counterResultsSummary) { | ||
// Found | ||
const fileFoundSeverityNumber = fileErrors.filter(err => { | ||
return err.severity === severity; | ||
}).length; | ||
// Fixed | ||
const fileFixedSeverityNumber = fileErrors.filter(err => { | ||
return err.severity === severity && err.fixed && err.fixed === true; | ||
}).length; | ||
// Remaining | ||
const fileRemainingSeverityNumber = fileFoundSeverityNumber - fileFixedSeverityNumber; | ||
// Add counters for each problem type | ||
for (const err of fileErrors) { | ||
counterResultsSummary.detectedRules[err.rule] = counterResultsSummary.detectedRules[err.rule] | ||
? counterResultsSummary.detectedRules[err.rule] + 1 | ||
: 1; | ||
if (err.fixed && err.fixed === true) { | ||
counterResultsSummary.fixedRules[err.rule] = counterResultsSummary.fixedRules[err.rule] | ||
? counterResultsSummary.fixedRules[err.rule] + 1 | ||
: 1; | ||
} | ||
} | ||
// Update summary & build result | ||
const severityCapital = `${severity[0].toUpperCase()}${severity.slice(1)}`; | ||
const totalFoundKey = `totalFound${severityCapital}Number`; | ||
const totalFixedKey = `totalFixed${severityCapital}Number`; | ||
const totalRemainingKey = `totalRemaining${severityCapital}Number`; | ||
counterResultsSummary[totalFoundKey] = counterResultsSummary[totalFoundKey] + fileFoundSeverityNumber; | ||
counterResultsSummary[totalFixedKey] = counterResultsSummary[totalFixedKey] + fileFixedSeverityNumber; | ||
counterResultsSummary[totalRemainingKey] = counterResultsSummary[totalRemainingKey] + fileRemainingSeverityNumber; | ||
return { | ||
found: fileFoundSeverityNumber, | ||
fixed: fileFixedSeverityNumber, | ||
remaining: fileRemainingSeverityNumber | ||
}; | ||
} | ||
// Reformat output if requested in command line | ||
@@ -85,0 +93,0 @@ async function processOutput(outputType, output, lintResult, options, fixer = null) { |
{ | ||
"name": "npm-groovy-lint", | ||
"version": "5.7.0", | ||
"version": "5.8.0", | ||
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -368,8 +368,12 @@ # NPM GROOVY LINT (+ Format & Auto-fix) | ||
[<img alt="nvuillam" src="https://avatars1.githubusercontent.com/u/17500430?v=4&s=50 width=50">](https://github.com/nvuillam) |[<img alt="docwhat" src="https://avatars1.githubusercontent.com/u/40799?v=4&s=50 width=50">](https://github.com/docwhat) |[<img alt="CatSue" src="https://avatars3.githubusercontent.com/u/26134618?v=4&s=50 width=50">](https://github.com/CatSue) |[<img alt="Dave Gallant" src="https://avatars2.githubusercontent.com/u/4519234?v=4&s=50 width=50">](https://github.com/davegallant) | | ||
[<img alt="nvuillam" src="https://avatars1.githubusercontent.com/u/17500430?v=4&s=50 width=50">](https://github.com/nvuillam) |[<img alt="Dave Gallant" src="https://avatars2.githubusercontent.com/u/4519234?v=4&s=50 width=50">](https://github.com/davegallant) |[<img alt="docwhat" src="https://avatars1.githubusercontent.com/u/40799?v=4&s=50 width=50">](https://github.com/docwhat) |[<img alt="CatSue" src="https://avatars3.githubusercontent.com/u/26134618?v=4&s=50 width=50">](https://github.com/CatSue) | | ||
:---:|:---:|:---:|:---:| | ||
[nvuillam](https://github.com/nvuillam)|[docwhat](https://github.com/docwhat)|[CatSue](https://github.com/CatSue)|[Dave Gallant](https://github.com/davegallant)| | ||
[nvuillam](https://github.com/nvuillam)|[Dave Gallant](https://github.com/davegallant)|[docwhat](https://github.com/docwhat)|[CatSue](https://github.com/CatSue)| | ||
## RELEASE NOTES | ||
### [5.8.0] 2020-08-01 | ||
- Fix & enhance anonymous statistics | ||
### [5.7.0] 2020-07-23 | ||
@@ -376,0 +380,0 @@ |
18788533
8122
454