Is there any way for jscs to ignore rules per file, block or line? - jscs

I'm looking for a way for jscs (JavaScript Code Style) do the same behavior as jshint to ignore certain rules per file with a comment at the top, or per line, with a start and end comment.
jshint example to ignore a specific rule in the file :
/* jshint undef: false */
jshint example to ignore a specific rule in a block:
// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be linted with ignored by JSHint.
/* jshint ignore:end */

This is available since jscs 1.6.0
For a file scope:
Put this on top of the file to ignore all rules
// jscs:disable
Put this on top of the file to ignore a specific rule:
// jscs:disable specificRule
Also for ignoring the whole file you can add it to .jscsrc, adding an entry to excludeFiles.
For block scope:
To ignore all rules
// Code here will be linted with JSCS.
// jscs:disable
// Code here will be ignored by JSCS.
// jscs:enable
To ignore a specific rule:
// Code here will be linted with JSCS.
// jscs:disable specificRule
// Code here will be ignored by JSCS.
// jscs:enable specificRule

to disable a particular rule for just the one line
// jscs:ignore maximumLineLength

To ignore the whole file just add the following line at the top of the file.
// jscs:disable

Related

Make Custom SwiftLint action regex ignore comments

I have a custom SwiftLint action to flag up print() statements:
custom_rules:
disable_print:
included: ".*\\.swift"
name: "print usage"
regex: "((\\bprint)|(Swift\\.print))\\s*\\("
message: "Don't use print"
severity: error
It works but it also flags whenever I have a print() statement specified in a documentation comment like this:
/// some comment mentioning print("hello") <- Error here
func myFunc() {}
How can I alter the regex so it ignores the print statement whenever it's in a documentation comment?
It seems that a custom rule can specify what type of code will match. The property is called match_kinds, example from Swiftlint Readme:
match_kinds: # SyntaxKinds to match. optional.
- comment
- identifier
Specifying identifier should be enough for your use case.

Include files via custom qmake function

I am new to the qmake and I'm experimenting with project structures.
I right now structured my project like
./src/
logic/
ui/
controller/
etc...
./inc/
logic/
ui/
controller/
etc...
I wanted to create a function that properly includes a new *.h and *.cpp file accordingly, so I did:
cont = "controller"
logic = "logic"
ui = "ui"
defineReplace(myFunction) {
path = $$1
name = $$2
HEADERS *= ./inc/$${path}/$${name}.h
SOURCES *= ./src/$${path}/$${name}.cpp
}
myFunction(cont,file1)
I expected the outcome to be as if I'd just put:
HEADERS *= ./inc/controller/file1.h
SOURCES *= ./src/controller/file1.cpp
But I just receive a myFunction is not a recognized test function.
What am I doing wrong?
What am I doing wrong?
Qmake makes a difference between "replace"-functions (i.e. returning a string, like variable substitution in make; typically used on the rhs of assignment) and "test"-functions (returning a boolean value suitable for conditional operator).
myFunction(cont, file) is a call of a test function; $$myFunction(cont, file) is a call of a replace function.
Also note that Qmake file basically consists of assignments and conditions. Therefore, myFunction(cont, file) is interpreted as
myFunction(cont, file) {
# nothing
} else {
# nothing
}
Another problem is that functions in Qmake work with own private copy of variables, so you must use export() to make your changes visible outside. Hence, we have:
# replace function example code
defineReplace(myFunction) {
HEADERS *= ./inc/$$1/$${2}.h
SOURCES *= ./src/$$1/$${2}.cpp
export(HEADERS)
export(SOURCES)
# warning: conditional must expand to exactly one word
#return()
# warning: conditional must expand to exactly one word
#return(foo bar)
# ok: any word will do as we don't care for true/false evaluation
return(baz)
}
# test function example code
defineTest(myFunction) {
HEADERS *= ./inc/$$1/$${2}.h
SOURCES *= ./src/$$1/$${2}.cpp
export(HEADERS)
export(SOURCES)
# warning: unexpected return value
#return(foo)
# ok: returns true
#return(true)
# ok: also returns true
#return()
# ...or simply return true by default
}
# calling replace function
$$myFunction(cont, file)
# calling test function
myFunction(cont, file)

Common epilogue code in every Bison action

I need to execute exactly the same block of code at the end of every action of Bison grammar rules. Currently, to achieve that, I need to manually write ACTION_EPILOGUE before each closing curly brace. Number of actions is huge, and I may easily forget to add it somewhere.
...
%start start
%%
...
start: keyword options
;
keyword: KEYWORD {
handle_keyword($1);
ACTION_EPILOGUE;
};
options: /* empty */
| option {ACTION_EPILOGUE;}
| options ',' option {ACTION_EPILOGUE;}
;
option: edit_option {ACTION_EPILOGUE;}
| delete_option {ACTION_EPILOGUE;}
;
edit_option: EDIT {
process_edit($1);
ACTION_EPILOGUE;
};
// more rules and actions
...
Is there an option/method to instruct Bison to add the same block of code to the end of each action?

Ant build task: how to change the basedir for an ant command (e.g. how to do a "cd") with grails 2.5

The below ant snippet from a target specified in grails "Scripts" dir, creates a single file with the checksums of all classes, so they can be checked on the target servers.
The output of the ant is a file like this:
c9b1c71b31e53e99ff31b4be0a1284558aa019ec target/classes/bo/ApiRequestFilters$_closure1.class
ff936fddc1b99ba323493b131d271ca4feb0f5dd target/classes/bo/ApiRequestFilters.class
df7a12fe1182b5fc10177a2559a3a0cbb0709e29 target/classes/com/xxx/yyy/apiConstants.class
The problem is the word "target" in the file path. When the app is deployed to tomcat under webapp, there is no target.
How can this be avoided? E.g. if the ant.concat function took a basedir:"target", if if you could do ant.cd("target") or similar it would solve the issue, or if you could specify a basedir per target, but this does not seem possible?
Source:
ant.checksum(fileext:".sha1", algorithm: "SHA", forceoverwrite: "yes", pattern: "{0} {3}") {
fileset(dir: "target/classes") {
include(name:"**/*.class")
}
}
ant.concat(destfile:"target/classes.sha1") {
fileset(dir: "target/classes") {
include(name:"**/*.sha1")
}
}
I found one hacky way - to remove the "target/" from the sha1 file after using:
ant.replace(file:"target/classes.sha1", token:" target/", value: " ")
Is there a better way?
For a small optimization improvement, consider removing the replace task by nesting a filterchain under concat.
In the following example, the replaceregex filter uses a regular expression to match lines starting with hash values followed by the string target/. If the beginning of the line matches, it is replaced with the target/ part deleted:
ant.concat(destfile:"target/classes.sha1") {
fileset(dir: "target/classes") {
include(name:"**/*.sha1")
}
filterchain {
tokenfilter {
// Using the regex "pattern" to match:
//
// "^": from the start of each line...
// "[0-9a-f]+": ...match as many hexadecimal characters as possible...
// " ": ...followed by a space character...
// "target/": ...followed by the string "target/".
//
// "([0-9a-f]+ )": captures the matching characters in group 1
//
// Then in "replace":
// "\\1": inserts capture group 1
//
replaceregex(pattern: "^([0-9a-f]+ )target/", replace: "\\1")
}
}
}
The above example avoids the I/O penalties of having concat write a file to disk followed by the replace task re-opening the file and re-writing it.

Resolving merge conflicts in the TFS API

I am trying to resolve merge conflicts with the TFS API and am struggling. My issue is as follows:
Merge from trunk -> branch
Conflict occurs during merge (same line of a file edited in both)
At this point I simply want to supply my own text for what the merged file should look like and then mark it as resolved.
I can't work out how to do this. See code below:
// merge was performed and there are conflicts to resolve
Conflict[] conflicts = ws.QueryConflicts(new string[] {"$/ProjectName/solution/"}, true);
Console.WriteLine(" - Conflicts: {0}", conflicts.Count());
if (conflicts.Any())
{
Console.WriteLine(" - Resolving conflicts");
// There are conflicts to deal with
foreach (Conflict conflict in conflicts)
{
// Attempt to perform merge internally
ws.MergeContent(conflict, false);
if (conflict.ContentMergeSummary.TotalConflicting > 0)
{
// Conflict was not resolved
// Manually resolve
// PROBLEM IS HERE <--------------
var allLines = File.ReadAllLines(conflict.TargetLocalItem).ToList();
allLines.Add("This is the MANUAL merge result");
File.WriteAllLines(conflict.TargetLocalItem, allLines.ToArray());
}
//conflict was resolved
conflict.Resolution = Resolution.AcceptMerge;
ws.ResolveConflict(conflict);
}
}
Checkin(ws, "Merge comment");
Console.WriteLine("Done");
As you can see I am trying to manually edit the target file, but this does not work. I can't seem to work out what file I should be editing on the conflict object to manually perform the merge.
One commenter has asked me to elaborate on the issues with the code above:
At the point of the comment "PROBLEM IS HERE", the target file still has a read only flag on it, so I cannot edit the file.
if I remove the readonly flag with some code and continue with the code, the resulting file does not contain my new line, but contains a diff style text with all the comments in. I can elaborate on this if it doesn't make sense.
If I pend an edit on the TargetLocalItem, this does nothing. No edit is pended.
This tells me that editing the target file in the local workspace is not the correct action.
Essentially I am trying to mimic what an external tool does, but my program will be the external tool and provide the merged text.
Try this
string tmpOutFile = Path.GetTempFileName();
conflict.MergedFileName = tmpOutFile;
// do stuff with tmpOutFile
conflict.Resolution = Resolution.AcceptMerge;
ws.ResolveConflict(conflict);

Resources