Skip to content

Commit c5874ac

Browse files
authored
Merge pull request #20 from codacy/fix-issues-with-no-lines
Fix exception when issues has no line
2 parents d74b478 + c0d5bc4 commit c5874ac

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

circle.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,33 @@ machine:
33
- echo 'DOCKER_OPTS="-s btrfs -e lxc -D --userland-proxy=false"' | sudo tee -a /etc/default/docker
44
- sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.0-circleci-cp-workaround'
55
- sudo chmod 0755 /usr/bin/docker
6+
- mkdir -p $HOME/.sbt/.lib/0.13.13 && wget https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.13/sbt-launch.jar -O $HOME/.sbt/.lib/0.13.13/sbt-launch.jar
7+
- (cd $HOME; rm -f codacy-plugins-test; git clone https://github.com/codacy/codacy-plugins-test.git)
68
java:
79
version: oraclejdk8
810
services:
911
- docker
1012

1113
dependencies:
1214
override:
13-
- sbt "set version in Docker := \"latest\"" "set name := \"$CIRCLE_PROJECT_REPONAME\"" docker:publishLocal
15+
- (cd $HOME/codacy-plugins-test && sbt compile)
16+
- (cd $HOME/$CIRCLE_PROJECT_REPONAME && sbt "set version in Docker := \"latest\"" "set name := \"$CIRCLE_PROJECT_REPONAME\"" docker:publishLocal)
17+
cache_directories:
18+
- "~/.ivy2"
19+
- "~/.m2"
20+
- "~/.sbt"
21+
- "~/codacy-plugins-test/target"
22+
- "~/codacy-plugins-test/project/target"
23+
- "~/codacy-plugins-test/project/project"
24+
- "~/$CIRCLE_PROJECT_REPONAME/target"
25+
- "~/$CIRCLE_PROJECT_REPONAME/project/target"
26+
- "~/$CIRCLE_PROJECT_REPONAME/project/project"
1427

1528
test:
1629
pre:
17-
- git clone https://github.com/codacy/codacy-plugins-test.git
30+
- (cd $HOME/codacy-plugins-test; git fetch --all; git reset --hard origin/master)
1831
override:
19-
- (cd codacy-plugins-test; sbt "run-main codacy.plugins.DockerTest all $CIRCLE_PROJECT_REPONAME:latest")
32+
- (cd $HOME/codacy-plugins-test && sbt -Dcodacy.tests.noremove=true -Dcodacy.tests.threads=8 "run-main codacy.plugins.DockerTest pattern $CIRCLE_PROJECT_REPONAME:latest")
2033

2134
deployment:
2235
hub:
@@ -25,4 +38,4 @@ deployment:
2538
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
2639
- docker tag $CIRCLE_PROJECT_REPONAME codacy/$CIRCLE_PROJECT_REPONAME
2740
- docker tag $CIRCLE_PROJECT_REPONAME codacy/$CIRCLE_PROJECT_REPONAME:1.0.$CIRCLE_BUILD_NUM
28-
- docker push codacy/$CIRCLE_PROJECT_REPONAME
41+
- docker push codacy/$CIRCLE_PROJECT_REPONAME

src/main/scala/codacy/pylint/Pylint.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,25 @@ object Pylint extends Tool {
5454
private implicit lazy val writer = Json.reads[Issue]
5555

5656
private def parseLine(line: String) = {
57-
val LineRegex = """(.*?)###(.*?)###(.*?)###(.*?)""".r
57+
val LineRegex = """(.*?)###(\d*?)###(.*?)###(.*?)""".r
58+
59+
def createIssue(filename: String, lineNumber: String, message: String, patternId: String) = {
60+
// If the pylint returns no line put the issue in the first line
61+
val issueLine = if (lineNumber.nonEmpty) lineNumber.toInt else 1
62+
Issue(SourcePath(filename),
63+
ResultMessage(message),
64+
PatternId(patternId),
65+
ResultLine(issueLine))
66+
}
67+
5868
line match {
5969
case LineRegex(filename, lineNumber, message, patternId) if message.contains("invalid syntax") =>
6070
val fileError = FileError(SourcePath(filename),
6171
Option(ErrorMessage(message)))
62-
val issue = Issue(SourcePath(filename),
63-
ResultMessage(message),
64-
PatternId(patternId),
65-
ResultLine(lineNumber.toInt))
72+
val issue = createIssue(filename, lineNumber, message, patternId)
6673
Option(List(fileError, issue))
6774
case LineRegex(filename, lineNumber, message, patternId) =>
68-
Option(List(Issue(SourcePath(filename),
69-
ResultMessage(message),
70-
PatternId(patternId),
71-
ResultLine(lineNumber.toInt))))
75+
Option(List(createIssue(filename, lineNumber, message, patternId)))
7276
case _ =>
7377
Option.empty
7478
}

0 commit comments

Comments
 (0)