npm-groovy-lint
Advanced tools
Comparing version 4.5.5 to 4.6.0
# Changelog | ||
## [4.6.0] 2020-05-01 | ||
- New fix rules | ||
- SpaceBeforeClosingBrace | ||
- UnnecessaryDefInMethodDeclaration | ||
- UnnecessaryPackageReference | ||
- UnnecessaryParenthesesForMethodCallWithClosure | ||
- Updated fix rules | ||
- MisorderedStaticImports: Fix `@Grapes` killer fixing rule | ||
- ElseBlockBrace :issue when instruction is on the same line than `else` | ||
## [4.5.5] 2020-04-30 | ||
@@ -47,3 +59,3 @@ | ||
- New fix rules (thanks [CatSue](https://github.com/CatSue) !): | ||
- SpaceAfterSemicolon | ||
- SpaceAfterSemicolon | ||
- SpaceAfterWhile | ||
@@ -86,3 +98,3 @@ | ||
- New option `nolintafter`: When format or fix is called, a new lint is performed after the fixes to update the error list. If you just want the updated source code and do not care about the error logs, use this parameter to improve performances | ||
- Fixes | ||
- Fixes | ||
- Manage correctly options `failonerror`, `failonwarning` and `failoninfo` | ||
@@ -175,3 +187,3 @@ - `npm-groovy-lint -version` now returns version from package.json | ||
- Update lines and ranges of other errors after a fix updated the number of lines | ||
- Generate automatically .groovylintrc-all.js during build | ||
- Generate automatically .groovylintrc-all.js during build | ||
- Split rules definition into files instead of all in a huge single file | ||
@@ -198,3 +210,3 @@ - Reorganize groovy-lint.js code, using codenarc-factory.js and codenarc-caller.js | ||
- Capability to fix errors | ||
- ConsecutiveBlankLines | ||
- ConsecutiveBlankLines | ||
- Indentation (IfStatementBraces and ElseIfStatementBraces must be manually fixed to have correct indentation) | ||
@@ -223,13 +235,7 @@ - IndentationComments (custom npm-groovy-rule triggered by Indentation rule) | ||
- Refactored documentation with detailed arguments description & examples | ||
___ | ||
## Before | ||
- I wasn't serious enough to keep a changelog, sorry ! | ||
- I wasn't serious enough to keep a changelog, sorry ! |
@@ -97,3 +97,3 @@ // Additional definition for codenarc rules ( get position & available fix) | ||
const rulesFixPriorityOrder = [ | ||
// Line rules or not changing line rules | ||
// Line rules or not changing number of lines rules | ||
"NoTabCharacter", | ||
@@ -114,3 +114,7 @@ "Indentation", | ||
"SpaceAfterSwitch", | ||
"SpaceBeforeClosingBrace", | ||
"UnnecessaryDefInFieldDeclaration", | ||
"UnnecessaryDefInMethodDeclaration", | ||
"UnnecessaryPackageReference", | ||
"UnnecessaryParenthesesForMethodCallWithClosure", | ||
"UnnecessarySemicolon", | ||
@@ -117,0 +121,0 @@ "TrailingWhitespace", |
// Missing else braces | ||
const { getOutOfBracesStrings, getStringRangeMultiline, getVariable, isValidCodeLine } = require("../utils"); | ||
const { containsOtherThan, getStringRangeMultiline, getVariable, isValidCodeLine } = require("../utils"); | ||
@@ -28,3 +28,3 @@ const rule = { | ||
line.includes(";") || | ||
getOutOfBracesStrings(line, ["else"]).length > 0 | ||
containsOtherThan(line, ["else", "}", "{", " "]) | ||
) { | ||
@@ -138,2 +138,21 @@ return allLines; | ||
codeNarcCallsNumber: 2 | ||
}, | ||
{ | ||
sourceBefore: ` | ||
static getFileExtension(fileName) { | ||
if (fileName.lastIndexOf('.') != -1 && fileName.lastIndexOf('.') != 0) { | ||
return fileName.substring(fileName.lastIndexOf('.') + 1) | ||
} | ||
else return '' | ||
} | ||
`, | ||
sourceAfter: ` | ||
static getFileExtension(fileName) { | ||
if (fileName.lastIndexOf('.') != -1 && fileName.lastIndexOf('.') != 0) { | ||
return fileName.substring(fileName.lastIndexOf('.') + 1) | ||
} | ||
else return '' | ||
} | ||
`, | ||
codeNarcCallsNumber: 1 | ||
} | ||
@@ -140,0 +159,0 @@ ] |
@@ -56,4 +56,4 @@ // Unused import | ||
for (const line of allLines) { | ||
// Comment line | ||
if (line.trimStart().startsWith("//")) { | ||
// Comment line preceding import | ||
if (line.trimStart().startsWith("//") && allLines[pos + 1].trim().startsWith("import")) { | ||
lastCommentFound = line; | ||
@@ -74,3 +74,3 @@ lastCommentFoundPos = pos; | ||
} | ||
// Update positions for later ibuild of ordered imports with comments | ||
// Update positions for later build of ordered imports with comments | ||
firstImportFoundPos = firstImportFoundPos || firstImportFoundPos === 0 ? firstImportFoundPos : pos; | ||
@@ -182,2 +182,55 @@ lastImportFoundPos = pos; | ||
` | ||
}, | ||
{ | ||
sourceBefore: ` | ||
// Blablabla grapes | ||
@Grapes([ | ||
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'), | ||
@Grab(group='com.google.guava', module='guava', version='19.0'), | ||
@Grab(group='org.apache.commons', module='commons-lang3', version='3.7') | ||
]) | ||
// Blablabla imports | ||
import groovy.io.FileType | ||
import groovy.transform.Field | ||
import groovy.xml.* | ||
import groovy.json.* | ||
import groovy.time.TimeCategory | ||
// Some other imports | ||
import java.io.File | ||
// Yeah my static imports | ||
import static groovyx.zpars.GParsPool.withPoolZ | ||
import static groovyx.gpars.GParsPool.withPool | ||
// And again other imports | ||
import after.all.does.it.work | ||
// The rest of the file below ... | ||
`, | ||
sourceAfter: ` | ||
// Blablabla grapes | ||
@Grapes([ | ||
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'), | ||
@Grab(group='com.google.guava', module='guava', version='19.0'), | ||
@Grab(group='org.apache.commons', module='commons-lang3', version='3.7') | ||
]) | ||
// Yeah my static imports | ||
import static groovyx.gpars.GParsPool.withPool | ||
import static groovyx.zpars.GParsPool.withPoolZ | ||
// Blablabla imports | ||
import groovy.io.FileType | ||
import groovy.json.* | ||
import groovy.time.TimeCategory | ||
import groovy.transform.Field | ||
import groovy.xml.* | ||
// Some other imports | ||
import java.io.File | ||
// And again other imports | ||
import after.all.does.it.work | ||
// The rest of the file below ... | ||
` | ||
} | ||
@@ -184,0 +237,0 @@ ] |
@@ -1,2 +0,2 @@ | ||
// Unnecessary def in field declaration (statif def) | ||
// Unnecessary def in field declaration (static def) | ||
@@ -3,0 +3,0 @@ const { getStringRange } = require("../utils"); |
@@ -239,5 +239,22 @@ // Shared functions | ||
// Checks that a string contains other things than a list of strings | ||
function containsOtherThan(str, stringArray) { | ||
const splits = splitMulti(str, stringArray); | ||
return splits.filter(item => item !== "").length > 0; | ||
} | ||
// Split with multiple characters | ||
function splitMulti(str, tokens) { | ||
var tempChar = tokens[0]; // We can use the first token as a temporary join character | ||
for (var i = 1; i < tokens.length; i++) { | ||
str = str.split(tokens[i]).join(tempChar); | ||
} | ||
str = str.split(tempChar); | ||
return str; | ||
} | ||
module.exports = { | ||
addSpaceAfterChar, | ||
addSpaceAroundChar, | ||
containsOtherThan, | ||
evaluateRange, | ||
@@ -244,0 +261,0 @@ evaluateVariables, |
{ | ||
"name": "npm-groovy-lint", | ||
"version": "4.5.5", | ||
"version": "4.6.0", | ||
"description": "NPM CodeNarc wrapper to easily lint Groovy files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -204,11 +204,11 @@ # NPM GROOVY LINT (+ Format & Auto-fix !) | ||
- BlockEndsWithBlankLine | ||
- BlockEndsWithBlankLine | ||
- BlockStartsWithBlankLine | ||
- ClassEndsWithBlankLine | ||
- ClassEndsWithBlankLine | ||
- ClassStartsWithBlankLine | ||
- ClosingBraceNotAlone | ||
- ConsecutiveBlankLines | ||
- ClosingBraceNotAlone | ||
- ConsecutiveBlankLines | ||
- ElseBlockBraces | ||
- FileEndsWithoutNewline | ||
- IfStatementBraces | ||
- FileEndsWithoutNewline | ||
- IfStatementBraces | ||
- Indentation | ||
@@ -228,7 +228,11 @@ - IndentationClosingBraces | ||
- SpaceAroundOperator | ||
- SpaceBeforeClosingBrace | ||
- SpaceBeforeOpeningBrace | ||
- TrailingWhitespace | ||
- UnnecessaryDefInFieldDeclaration | ||
- UnnecessaryDefInMethodDeclaration | ||
- UnnecessaryGString | ||
- UnnecessaryGroovyImport | ||
- UnnecessaryPackageReference | ||
- UnnecessaryParenthesesForMethodCallWithClosure | ||
- UnnecessarySemicolon | ||
@@ -235,0 +239,0 @@ - UnnecessaryToString |
16394308
106
5220
288