npm-groovy-lint
Advanced tools
Comparing version 10.0.3 to 10.1.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [10.1.0] 2022-08-15 | ||
- Allow to send groovy sources as input from stdin | ||
- If `--format` or `--fix` option is used when source is sent as stdin, the result is output as stdout | ||
Example: `cat path/to/my/Jenkinsfile | npm-groovy-lint --format -` | ||
## [10.0.3] 2022-08-15 | ||
@@ -7,0 +14,0 @@ |
@@ -139,3 +139,3 @@ // Shared functions | ||
if ( | ||
["txt", "json", "sarif", "none"].includes(result.output) || | ||
["txt", "json", "sarif", "none", "stdout"].includes(result.output) || | ||
result.output.endsWith(".txt") || | ||
@@ -142,0 +142,0 @@ result.output.endsWith(".sarif") || |
// Imports | ||
const debug = require("debug")("npm-groovy-lint"); | ||
const fs = require("fs-extra"); | ||
const os = require("os"); | ||
@@ -140,2 +141,13 @@ const performance = require("perf_hooks").performance; | ||
} | ||
// Try to catch input from stdin. if found, use it as groovy source | ||
if (this.options._ && this.options._[0] === '-') { | ||
const stdInData = fs.readFileSync(0, 'utf-8'); | ||
this.options.source = stdInData; | ||
this.options._ = []; | ||
this.options.sourcefilepath = this.options.sourcefilepath || process.cwd(); | ||
if (this.options.format || this.options.fix) { | ||
this.options.output = 'stdout'; | ||
} | ||
} | ||
} catch (err) { | ||
@@ -479,3 +491,3 @@ this.status = 2; | ||
if (failureLevel === "error" && errorNb > 0) { | ||
if (!["json", "sarif"].includes(this.outputType)) { | ||
if (!["json", "sarif", "stdout"].includes(this.outputType)) { | ||
console.error(`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found`); | ||
@@ -487,3 +499,3 @@ } | ||
else if (failureLevel === "warning" && (errorNb > 0 || warningNb > 0)) { | ||
if (!["json", "sarif"].includes(this.outputType)) { | ||
if (!["json", "sarif", "stdout"].includes(this.outputType)) { | ||
console.error( | ||
@@ -497,3 +509,3 @@ `Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found` | ||
else if (failureLevel === "info" && (errorNb > 0 || warningNb > 0 || infoNb > 0)) { | ||
if (!["json", "sarif"].includes(this.outputType)) { | ||
if (!["json", "sarif", "stdout"].includes(this.outputType)) { | ||
console.error( | ||
@@ -500,0 +512,0 @@ `Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found \n ${this.lintResult.summary.totalFoundInfoNumber} info(s) have been found` |
@@ -208,3 +208,5 @@ // Output management | ||
} | ||
} else if (outputType === "sarif") { | ||
} | ||
// SARIF results | ||
else if (outputType === "sarif") { | ||
const sarifJsonString = buildSarifResult(lintResult); | ||
@@ -223,2 +225,6 @@ // SARIF file | ||
} | ||
// stdout result for format / fix with source sent as stdin | ||
else if (outputType === "stdout") { | ||
console.log(lintResult.files[0].updatedSource); | ||
} | ||
return outputString; | ||
@@ -225,0 +231,0 @@ } |
{ | ||
"name": "npm-groovy-lint", | ||
"version": "10.0.3", | ||
"version": "10.1.0", | ||
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
108
README.md
@@ -46,4 +46,2 @@ <!-- markdownlint-disable MD013 MD033 MD034 --> | ||
See [examples](#example-calls) | ||
| Parameter | Type | Description | | ||
@@ -76,2 +74,64 @@ |-------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
### Example calls | ||
- Lint a file | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/file.groovy | ||
``` | ||
- Lint multiple files | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy | ||
``` | ||
- Lint directory | ||
```shell | ||
npm-groovy-lint path/to/my/groovy | ||
``` | ||
- Lint pattern | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/*.groovy | ||
``` | ||
- Lint groovy with JSON output | ||
```shell | ||
npm-groovy-lint --output json | ||
``` | ||
- Format files | ||
```shell | ||
npm-groovy-lint --format my/path/to/file.groovy my/path/to/file2.groovy | ||
``` | ||
- Format and fix files | ||
```shell | ||
npm-groovy-lint --fix my/path/to/file.groovy my/path/to/file2.groovy | ||
``` | ||
- Get formatted sources in stdout from stdin | ||
```shell | ||
cat path/to/my/Jenkinsfile | npm-groovy-lint --format - | ||
``` | ||
- Advanced config | ||
```shell | ||
npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt | ||
``` | ||
- Lint using core CodeNarc parameters and generate HTML report file | ||
```shell | ||
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html" | ||
``` | ||
## Installation | ||
@@ -150,46 +210,2 @@ | ||
## Example calls | ||
- Lint a file | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/file.groovy | ||
``` | ||
- Lint multiple files | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/file.groovy path/to/my/groovy/file2.groovy path/to/my/groovy/file3.groovy | ||
``` | ||
- Lint directory | ||
```shell | ||
npm-groovy-lint path/to/my/groovy | ||
``` | ||
- Lint pattern | ||
```shell | ||
npm-groovy-lint path/to/my/groovy/*.groovy | ||
``` | ||
- Lint groovy with JSON output | ||
```shell | ||
npm-groovy-lint --output json | ||
``` | ||
- Advanced config | ||
```shell | ||
npm-groovy-lint --path "./path/to/my/groovy/files" --files "**/*.groovy" --config "./config/codenarc/.groovylintrcCustom.js" --loglevel warning --output txt | ||
``` | ||
- Lint using core CodeNarc parameters and generate HTML report file | ||
```shell | ||
npm-groovy-lint --codenarcargs -basedir="lib/example" -rulesetfiles="file:lib/example/RuleSet-Groovy.groovy" -title="TestTitleCodenarc" -maxPriority1Violations=0' -report="html:ReportTestCodenarc.html" | ||
``` | ||
## Disabling rules in source | ||
@@ -196,0 +212,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16992896
7278
455
21