Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added file property in ant task xml for check single js file #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added release/ant-jshint-0.3.6-SNAPSHOT-deps-bin.zip
Binary file not shown.
Binary file modified release/ant-jshint-0.3.6-SNAPSHOT-deps.jar
Binary file not shown.
41 changes: 31 additions & 10 deletions src/main/java/com/philmander/jshint/JsHintAntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class JsHintAntTask extends MatchingTask implements JsHintLogger {
private final String JSHINTRC_FILE = ".jshintrc";

private File dir;

private File file; //for single js file

private boolean fail = true;

Expand All @@ -66,12 +68,18 @@ public void addConfiguredReport(ReportType report) {
public void execute() throws BuildException {

checkAttributes();

DirectoryScanner dirScanner = getDirectoryScanner(dir);
String[] files = dirScanner.getIncludedFiles();

log("Validating files in " + dir.getAbsolutePath());


String[] files = new String[]{};
if (dir != null) {
DirectoryScanner dirScanner = getDirectoryScanner(dir);
files = dirScanner.getIncludedFiles();
log("Validating files in " + dir.getAbsolutePath());
} else if (file != null) {
dir = file.getParentFile(); //içinde bulunduğu dizin
files = new String[]{file.getName()}; //kısa ismi
log("Validating file " + file.getAbsolutePath());
}

if (files.length > 0) {

try {
Expand Down Expand Up @@ -224,12 +232,16 @@ private void reportResults(JsHintReport report) {
private void checkAttributes() {
String message = null;

if (dir == null) {
message = "Missing dir attribute";
} else if (!dir.exists()) {
if (dir == null && file == null) {
message = "Missing dir or file attribute";
} else if (dir != null && !dir.exists()) {
message = "Directoy does not exist";
} else if (!dir.isDirectory()) {
} else if (dir != null && !dir.isDirectory()) {
message = "Dir is not a directory";
} else if (file != null && !file.exists()) {
message = "File does not exist";
} else if (file != null && file.isDirectory()) {
message = "File is a directory";
}
if (message != null) {
throw new BuildException(message);
Expand All @@ -246,6 +258,15 @@ public void setDir(File dir) {
}

/**
* The file for validate.
* validate js file and excludes to omit file such as compressed js
* librarie from js validation
*/
public void setFile(File file) {
this.file = file;
}

/**
* By default the ant task will fail the build if jshint finds any errors.
* Set this to false for reporting purposes
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/philmander/jshint/JsHintRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public JsHintReport lint(String[] files, Map<Object, Object> options, Map<Object
result.addError(hintError);

if (logger != null) {
logger.log(PlainJsHintReporter.getIssueMessage(reason, evidence, line, character));
logger.log(PlainJsHintReporter.getIssueMessage(jsFileName, reason, evidence, line, character));
}
} catch (ClassCastException e) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String createReport() {
output.append("\n");
output.append(getFileFailureMessage((result.getFile()) + "\n"));
for(JsHintError error : result.getErrors()) {
output.append(getIssueMessage(error.getReason(), error.getEvidence(), error.getLine(), error.getCharacter()) + "\n");
output.append(getIssueMessage(result.getFile(), error.getReason(), error.getEvidence(), error.getLine(), error.getCharacter()) + "\n");
}

}
Expand All @@ -56,8 +56,11 @@ public static String getFileFailureMessage(String file) {
return "JSHint validation failed for " + file;
}

public static String getIssueMessage(String reason, String evidence, int line, int character) {
String msg = reason + " (line: " + line + ", character: " + character + ")\n > " + evidence;
public static String getIssueMessage(String file, String reason, String evidence, int line, int character) {
//String msg = reason + " (line: " + line + ", character: " + character + ")\n > " + evidence;
//running in IDE, after ant task run, we can click js file name and goto source file and line
//so added file name ve line
String msg = file + ":" + line + ":" + " " + reason + " " + evidence;
return msg;
}

Expand Down