Skip to content

Commit

Permalink
Merge pull request CSSLint#482 from XhmikosR/jshint
Browse files Browse the repository at this point in the history
Stricter JSHint rules
  • Loading branch information
nschonni committed May 2, 2014
2 parents a422b00 + 856902f commit 5d69c54
Show file tree
Hide file tree
Showing 100 changed files with 182 additions and 53 deletions.
5 changes: 3 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"camelcase": true,
"curly": true,
"eqnull": true,
"eqeqeq": true,
"forin": true,
"immed": true,
"indent": 4,
Expand All @@ -11,8 +11,9 @@
"noempty": true,
"nonbsp": true,
"quotmark": "double",
"unused": true,
"strict": true,
"undef": true,
"unused": true,
"globals": {
"CSSLint": true,
"YUITest": true
Expand Down
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* jshint camelcase:false, evil:true, node:true */

"use strict";

module.exports = function(grunt) {

// Project configuration.
Expand Down
3 changes: 2 additions & 1 deletion demos/CSSLintDemo.htm
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ <h1>CSSLint Demo</h1>
<div id="output"></div>
<script>
(function() {
"use strict";

document.body.onclick = function(event) {
event = event || window.event;
var target = event.target || event.srcElement,
results, messages, i, len;


if (target.id == "lint-btn") {
if (target.id === "lint-btn") {
document.getElementById("output").innerHTML = "";
results = CSSLint.verify(document.getElementById("input").value);
messages = results.messages;
Expand Down
1 change: 1 addition & 0 deletions src/cli/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* exported cli */

function cli(api){
"use strict";

var globalOptions = {
"help" : { "format" : "", "description" : "Displays this information."},
Expand Down
9 changes: 8 additions & 1 deletion src/cli/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ cli({
args: process.argv.slice(2),

print: function(message){
"use strict";
fs.writeSync(1, message + "\n");
},

quit: function(code){
"use strict";
process.exit(code || 0);
},

isDirectory: function(name){
"use strict";
try {
return fs.statSync(name).isDirectory();
} catch (ex) {
Expand All @@ -30,6 +33,7 @@ cli({
},

getFiles: function(dir){
"use strict";
var files = [];

try {
Expand All @@ -44,7 +48,7 @@ cli({
var path = stack.concat([file]).join("/"),
stat = fs.statSync(path);

if (file[0] == ".") {
if (file[0] === ".") {
return;
} else if (stat.isFile() && /\.css$/.test(file)){
files.push(path);
Expand All @@ -61,14 +65,17 @@ cli({
},

getWorkingDirectory: function() {
"use strict";
return process.cwd();
},

getFullPath: function(filename){
"use strict";
return path.resolve(process.cwd(), filename);
},

readFile: function(filename){
"use strict";
try {
return fs.readFileSync(filename, "utf-8");
} catch (ex) {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/rhino.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
importPackage(java.io);

cli({

args: Array.prototype.concat.call(arguments),
print: print,
quit: quit,

isDirectory: function(name){
"use strict";
var dir = new File(name);
return dir.isDirectory();
},

getFiles: function(dir){
"use strict";
var files = [];

function traverse(dir) {
Expand All @@ -37,14 +40,17 @@ cli({
},

getWorkingDirectory: function() {
"use strict";
return (new File(".")).getCanonicalPath();
},

getFullPath: function(filename){
"use strict";
return (new File(filename)).getCanonicalPath();
},

readFile: function(filename) {
"use strict";
try {
return readFile(filename);
} catch (ex) {
Expand Down
5 changes: 3 additions & 2 deletions src/cli/wsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/* global cli */

var wshapi = (function(){
"use strict";

var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var finalArgs = [], i, args = WScript.Arguments;
Expand All @@ -22,7 +24,7 @@ var wshapi = (function(){

if (typeof Array.prototype.filter !== "function") {
Array.prototype.filter = function(fn /*, thisp*/) {
if (typeof fn != "function") {
if (typeof fn !== "function") {
throw new Error("not a function");
}
var res = [], val, thisp = finalArgs[1];
Expand All @@ -41,7 +43,6 @@ var wshapi = (function(){

if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this === void 0 || this === null) {
throw new Error("unknown instance");
}
Expand Down
1 change: 1 addition & 0 deletions src/core/CSSLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* exported CSSLint */

var CSSLint = (function(){
"use strict";

var rules = [],
formatters = [],
Expand Down
10 changes: 9 additions & 1 deletion src/core/Reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* they are errors or warnings.
*/
function Reporter(lines, ruleset){
"use strict";

/**
* List of messages being reported.
Expand Down Expand Up @@ -54,6 +55,7 @@ Reporter.prototype = {
* @method error
*/
error: function(message, line, col, rule){
"use strict";
this.messages.push({
type : "error",
line : line,
Expand All @@ -74,6 +76,7 @@ Reporter.prototype = {
* @deprecated Use report instead.
*/
warn: function(message, line, col, rule){
"use strict";
this.report(message, line, col, rule);
},

Expand All @@ -86,8 +89,9 @@ Reporter.prototype = {
* @method report
*/
report: function(message, line, col, rule){
"use strict";
this.messages.push({
type : this.ruleset[rule.id] == 2 ? "error" : "warning",
type : this.ruleset[rule.id] === 2 ? "error" : "warning",
line : line,
col : col,
message : message,
Expand All @@ -105,6 +109,7 @@ Reporter.prototype = {
* @method info
*/
info: function(message, line, col, rule){
"use strict";
this.messages.push({
type : "info",
line : line,
Expand All @@ -122,6 +127,7 @@ Reporter.prototype = {
* @method rollupError
*/
rollupError: function(message, rule){
"use strict";
this.messages.push({
type : "error",
rollup : true,
Expand All @@ -137,6 +143,7 @@ Reporter.prototype = {
* @method rollupWarn
*/
rollupWarn: function(message, rule){
"use strict";
this.messages.push({
type : "warning",
rollup : true,
Expand All @@ -152,6 +159,7 @@ Reporter.prototype = {
* @method stat
*/
stat: function(name, value){
"use strict";
this.stats[name] = value;
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/core/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CSSLint.Util = {
* @return {Object} The receiver
*/
mix: function(receiver, supplier){
"use strict";
var prop;

for (prop in supplier){
Expand All @@ -29,6 +30,7 @@ CSSLint.Util = {
* @return {int} The index of the value if found, -1 if not.
*/
indexOf: function(values, value){
"use strict";
if (values.indexOf){
return values.indexOf(value);
} else {
Expand All @@ -48,6 +50,7 @@ CSSLint.Util = {
* @return {void}
*/
forEach: function(values, func) {
"use strict";
if (values.forEach){
return values.forEach(func);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/formatters/checkstyle-xml.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function() {
"use strict";

/**
* Replace special characters before write to output.
Expand Down
5 changes: 4 additions & 1 deletion src/formatters/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CSSLint.addFormatter({
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "";
},

Expand All @@ -16,6 +17,7 @@ CSSLint.addFormatter({
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "";
},

Expand All @@ -27,6 +29,7 @@ CSSLint.addFormatter({
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
"use strict";
var messages = results.messages,
output = "";
options = options || {};
Expand All @@ -41,7 +44,7 @@ CSSLint.addFormatter({
};

if (messages.length === 0) {
return options.quiet ? "" : filename + ": Lint Free!";
return options.quiet ? "" : filename + ": Lint Free!";
}

CSSLint.Util.forEach(messages, function(message) {
Expand Down
3 changes: 3 additions & 0 deletions src/formatters/csslint-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CSSLint.addFormatter({
* @return {String} to prepend before all results
*/
startFormat: function(){
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
},

Expand All @@ -16,6 +17,7 @@ CSSLint.addFormatter({
* @return {String} to append after all results
*/
endFormat: function(){
"use strict";
return "</csslint>";
},

Expand All @@ -27,6 +29,7 @@ CSSLint.addFormatter({
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";
var messages = results.messages,
output = [];

Expand Down
3 changes: 3 additions & 0 deletions src/formatters/junit-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CSSLint.addFormatter({
* @return {String} to prepend before all results
*/
startFormat: function(){
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
},

Expand All @@ -16,6 +17,7 @@ CSSLint.addFormatter({
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "</testsuites>";
},

Expand All @@ -27,6 +29,7 @@ CSSLint.addFormatter({
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";

var messages = results.messages,
output = [],
Expand Down
3 changes: 3 additions & 0 deletions src/formatters/lint-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CSSLint.addFormatter({
* @return {String} to prepend before all results
*/
startFormat: function(){
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
},

Expand All @@ -16,6 +17,7 @@ CSSLint.addFormatter({
* @return {String} to append after all results
*/
endFormat: function(){
"use strict";
return "</lint>";
},

Expand All @@ -27,6 +29,7 @@ CSSLint.addFormatter({
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";
var messages = results.messages,
output = [];

Expand Down
Loading

0 comments on commit 5d69c54

Please sign in to comment.