Skip to content

Commit

Permalink
Merge JSHint checkstyle feature from @levsa
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Apr 6, 2013
2 parents 5b03603 + 02d4135 commit d4d2868
Show file tree
Hide file tree
Showing 7 changed files with 5,114 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targetCompatibility = '1.6'

defaultTasks 'clean', 'build'

version = '1.4.2'
version = '1.5.0'
group = 'com.eriwen'
ext.archivesBaseName = 'gradle-js-plugin'
ext.isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
5 changes: 3 additions & 2 deletions plugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.4.1'
classpath 'com.eriwen:gradle-js-plugin:1.5.0'
}
}
buildscript {
Expand Down Expand Up @@ -75,7 +75,8 @@ task gzip(type: com.eriwen.gradle.js.tasks.GzipJsTask) {
task jshintz(type: com.eriwen.gradle.js.tasks.JsHintTask) {
source = javascript.source.custom.js.files
dest = "${buildDir}/jshint.out"
ignoreExitCode = false
ignoreExitCode = true
reporter = 'checkstyle'
jshint.options = [expr: "true", unused: "true"]
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/eriwen/gradle/js/RhinoExec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RhinoExec {
def execOptions = {
main = RHINO_MAIN_CLASS
classpath = project.configurations.rhino
args = execargs
args = ["-opt", "9"] + execargs
workingDir = workingDirIn
ignoreExitValue = ignoreExitCode
standardOutput = out
Expand Down
10 changes: 9 additions & 1 deletion src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.OutputFile

class JsHintTask extends SourceTask {
private static final String JSHINT_PATH = 'jshint-rhino-r12.js'
private static final String JSHINT_PATH = 'jshint-rhino-cs-r12.js'
private static final String TMP_DIR = "tmp${File.separator}js"
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private final RhinoExec rhino = new RhinoExec(project)

@OutputFile def dest = new File(project.buildDir, "jshint.log")
@Input def ignoreExitCode = true
@Input def outputToStdOut = false
@Input def reporter = ''

File getDest() {
project.file(dest)
Expand All @@ -42,6 +43,13 @@ class JsHintTask extends SourceTask {
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll(source.files.collect { it.canonicalPath })

// Allow variable reporter
if (reporter) {
logger.debug("reporter=${reporter}")
args.add("reporter=${reporter}")
}

LinkedHashMap<String, Object> options = project.jshint.options
if (options != null && options.size() > 0) {
def optionsArg = ""
Expand Down
5,071 changes: 5,071 additions & 0 deletions src/main/resources/jshint-rhino-cs-r12.js

Large diffs are not rendered by default.

Empty file modified src/main/resources/jshint-rhino-r12.js
100755 → 100644
Empty file.
30 changes: 29 additions & 1 deletion src/test/groovy/com/eriwen/gradle/js/JsHintTaskTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class JsHintTaskTest extends Specification {
Project project = ProjectBuilder.builder().build()
def task
def src
def dest

def setup() {
project.apply(plugin: JsPlugin)
task = project.tasks.jshint
src = dir.newFolder()
dest = dir.newFile()
task.source = src
task.dest = dir.newFile()
task.dest = dest
}

def "build ignores result by default"() {
Expand Down Expand Up @@ -89,6 +91,32 @@ class JsHintTaskTest extends Specification {
notThrown ExecException
}

def "does not generate checkstyle report when disabled"() {
given:
task.checkstyle = false
addFile("invalid.js", "var b = 5")

when:
task.run()

then:
def contents = new File(dest as String).text
assert ! (contents =~ "<checkstyle")
}

def "generates checkstyle report when enabled"() {
given:
task.reporter = 'checkstyle'
addFile("invalid.js", "var b = 5")

when:
task.run()

then:
def contents = new File(dest as String).text
assert contents =~ "<checkstyle"
}

def addValidFile() {
addFile("valid.js", "var a = 5;")
}
Expand Down

0 comments on commit d4d2868

Please sign in to comment.