coffeelint/lib/coffeelint.js in coffeelint-0.2.0 vs coffeelint/lib/coffeelint.js in coffeelint-0.2.1

- old
+ new

@@ -1,11 +1,10 @@ -(function(e){if("function"==typeof bootstrap)bootstrap("coffeelint",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeCoffeelint=e}else"undefined"!=typeof window?window.coffeelint=e():global.coffeelint=e()})(function(){var define,ses,bootstrap,module,exports; -return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ +!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.coffeelint=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ module.exports={ "name": "coffeelint", "description": "Lint your CoffeeScript", - "version": "1.0.6", + "version": "1.1.0", "homepage": "http://www.coffeelint.org", "keywords": [ "lint", "coffeescript", "coffee-script" @@ -22,14 +21,14 @@ "bin": { "coffeelint": "./bin/coffeelint" }, "dependencies": { "optimist": ">=0.2.8", - "coffee-script": ">=1.6.0", + "coffee-script": "~1.7", "glob": ">=3.1.9", - "browserify": "~2.26.0", - "coffeeify": "~0.5.1" + "browserify": "~3.x", + "coffeeify": "~0.6.0" }, "devDependencies": { "vows": ">=0.6.0", "underscore": ">=1.4.4" }, @@ -38,28 +37,29 @@ "type": "MIT", "url": "http://github.com/clutchski/coffeelint/raw/master/LICENSE" } ], "scripts": { - "pretest": "npm run compile", - "test": "vows --spec test/*.coffee test/*.litcoffee", + "pretest": "cake compile", + "test": "coffee vowsrunner.coffee --spec test/*.coffee test/*.litcoffee", "posttest": "npm run lint", - "prepublish": "npm run compile", - "install": "echo 'process.exit(require(\"fs\").existsSync(\"lib/commandline.js\") ? 0 : 1)' | node || npm run compile", - "lint": "npm run compile && ./bin/coffeelint -f coffeelint.json src/*.coffee test/*.coffee test/*.litcoffee", - "lint-csv": "npm run compile && ./bin/coffeelint --csv -f coffeelint.json src/*.coffee test/*.coffee", - "lint-jslint": "npm run compile && ./bin/coffeelint --jslint -f coffeelint.json src/*.coffee test/*.coffee", - "compile": "coffee -c -o lib src && ./node_modules/browserify/bin/cmd.js -t coffeeify -s coffeelint -e src/coffeelint.coffee > lib/coffeelint.js" + "prepublish": "cake prepublish", + "publish": "cake publish", + "install": "cake install", + "lint": "cake compile && ./bin/coffeelint -f coffeelint.json src/*.coffee test/*.coffee test/*.litcoffee", + "lint-csv": "cake compile && ./bin/coffeelint --csv -f coffeelint.json src/*.coffee test/*.coffee", + "lint-jslint": "cake compile && ./bin/coffeelint --jslint -f coffeelint.json src/*.coffee test/*.coffee", + "compile": "cake compile" } } -},{}],2:[function(require,module,exports){ +},{}],2:[function(_dereq_,module,exports){ var ASTApi, ASTLinter, BaseLinter, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; -BaseLinter = require('./base_linter.coffee'); +BaseLinter = _dereq_('./base_linter.coffee'); ASTApi = (function() { function ASTApi(config) { this.config = config; } @@ -80,12 +80,11 @@ ASTLinter.prototype.acceptRule = function(rule) { return typeof rule.lintAST === 'function'; }; ASTLinter.prototype.lint = function() { - var coffeeError, err, errors, rule, v, _i, _len, _ref, - _this = this; + var coffeeError, err, errors, rule, v, _i, _len, _ref; errors = []; try { this.node = this.CoffeeScript.nodes(this.source); } catch (_error) { coffeeError = _error; @@ -96,16 +95,18 @@ return errors; } _ref = this.rules; for (_i = 0, _len = _ref.length; _i < _len; _i++) { rule = _ref[_i]; - this.astApi.createError = function(attrs) { - if (attrs == null) { - attrs = {}; - } - return _this.createError(rule.rule.name, attrs); - }; + this.astApi.createError = (function(_this) { + return function(attrs) { + if (attrs == null) { + attrs = {}; + } + return _this.createError(rule.rule.name, attrs); + }; + })(this); rule.errors = errors; v = this.normalizeResult(rule, rule.lintAST(this.node, this.astApi)); if (v != null) { return v; } @@ -137,11 +138,11 @@ return ASTLinter; })(BaseLinter); -},{"./base_linter.coffee":3}],3:[function(require,module,exports){ +},{"./base_linter.coffee":3}],3:[function(_dereq_,module,exports){ var BaseLinter, defaults, extend, __slice = [].slice; extend = function() { var destination, k, source, sources, v, _i, _len; @@ -230,42 +231,42 @@ return BaseLinter; })(); -},{}],4:[function(require,module,exports){ +},{}],4:[function(_dereq_,module,exports){ + /* CoffeeLint Copyright (c) 2011 Matthew Perpick. CoffeeLint is freely distributable under the MIT license. -*/ - + */ var ASTLinter, CoffeeScript, ERROR, IGNORE, LexicalLinter, LineLinter, RULES, WARN, coffeelint, cs, defaults, difference, extend, hasSyntaxError, mergeDefaultConfig, packageJSON, _rules, __slice = [].slice, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; coffeelint = exports; if (typeof window !== "undefined" && window !== null) { CoffeeScript = window.CoffeeScript; } else { cs = 'coffee-script'; - CoffeeScript = require(cs); + CoffeeScript = _dereq_(cs); } -packageJSON = require('./../package.json'); +packageJSON = _dereq_('./../package.json'); coffeelint.VERSION = packageJSON.version; ERROR = 'error'; WARN = 'warn'; IGNORE = 'ignore'; -coffeelint.RULES = RULES = require('./rules.coffee'); +coffeelint.RULES = RULES = _dereq_('./rules.coffee'); extend = function() { var destination, k, source, sources, v, _i, _len; destination = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : []; for (_i = 0, _len = sources.length; _i < _len; _i++) { @@ -294,15 +295,15 @@ } } return _results; }; -LineLinter = require('./line_linter.coffee'); +LineLinter = _dereq_('./line_linter.coffee'); -LexicalLinter = require('./lexical_linter.coffee'); +LexicalLinter = _dereq_('./lexical_linter.coffee'); -ASTLinter = require('./ast_linter.coffee'); +ASTLinter = _dereq_('./ast_linter.coffee'); mergeDefaultConfig = function(userConfig) { var config, rule, ruleConfig; config = {}; for (rule in RULES) { @@ -367,57 +368,57 @@ } RULES[p.rule.name] = p.rule; return _rules[p.rule.name] = RuleConstructor; }; -coffeelint.registerRule(require('./rules/arrow_spacing.coffee')); +coffeelint.registerRule(_dereq_('./rules/arrow_spacing.coffee')); -coffeelint.registerRule(require('./rules/no_tabs.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_tabs.coffee')); -coffeelint.registerRule(require('./rules/no_trailing_whitespace.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_trailing_whitespace.coffee')); -coffeelint.registerRule(require('./rules/max_line_length.coffee')); +coffeelint.registerRule(_dereq_('./rules/max_line_length.coffee')); -coffeelint.registerRule(require('./rules/line_endings.coffee')); +coffeelint.registerRule(_dereq_('./rules/line_endings.coffee')); -coffeelint.registerRule(require('./rules/no_trailing_semicolons.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_trailing_semicolons.coffee')); -coffeelint.registerRule(require('./rules/indentation.coffee')); +coffeelint.registerRule(_dereq_('./rules/indentation.coffee')); -coffeelint.registerRule(require('./rules/camel_case_classes.coffee')); +coffeelint.registerRule(_dereq_('./rules/camel_case_classes.coffee')); -coffeelint.registerRule(require('./rules/colon_assignment_spacing.coffee')); +coffeelint.registerRule(_dereq_('./rules/colon_assignment_spacing.coffee')); -coffeelint.registerRule(require('./rules/no_implicit_braces.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_implicit_braces.coffee')); -coffeelint.registerRule(require('./rules/no_plusplus.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_plusplus.coffee')); -coffeelint.registerRule(require('./rules/no_throwing_strings.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_throwing_strings.coffee')); -coffeelint.registerRule(require('./rules/no_backticks.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_backticks.coffee')); -coffeelint.registerRule(require('./rules/no_implicit_parens.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_implicit_parens.coffee')); -coffeelint.registerRule(require('./rules/no_empty_param_list.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_empty_param_list.coffee')); -coffeelint.registerRule(require('./rules/no_stand_alone_at.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_stand_alone_at.coffee')); -coffeelint.registerRule(require('./rules/space_operators.coffee')); +coffeelint.registerRule(_dereq_('./rules/space_operators.coffee')); -coffeelint.registerRule(require('./rules/duplicate_key.coffee')); +coffeelint.registerRule(_dereq_('./rules/duplicate_key.coffee')); -coffeelint.registerRule(require('./rules/empty_constructor_needs_parens.coffee')); +coffeelint.registerRule(_dereq_('./rules/empty_constructor_needs_parens.coffee')); -coffeelint.registerRule(require('./rules/cyclomatic_complexity.coffee')); +coffeelint.registerRule(_dereq_('./rules/cyclomatic_complexity.coffee')); -coffeelint.registerRule(require('./rules/newlines_after_classes.coffee')); +coffeelint.registerRule(_dereq_('./rules/newlines_after_classes.coffee')); -coffeelint.registerRule(require('./rules/no_unnecessary_fat_arrows.coffee')); +coffeelint.registerRule(_dereq_('./rules/no_unnecessary_fat_arrows.coffee')); -coffeelint.registerRule(require('./rules/missing_fat_arrows.coffee')); +coffeelint.registerRule(_dereq_('./rules/missing_fat_arrows.coffee')); -coffeelint.registerRule(require('./rules/non_empty_constructor_needs_parens.coffee')); +coffeelint.registerRule(_dereq_('./rules/non_empty_constructor_needs_parens.coffee')); hasSyntaxError = function(source) { try { CoffeeScript.tokens(source); return false; @@ -462,11 +463,11 @@ if (!hasSyntaxError(source)) { lexicalLinter = new LexicalLinter(source, config, _rules, CoffeeScript); lexErrors = lexicalLinter.lint(); errors = errors.concat(lexErrors); tokensByLine = lexicalLinter.tokensByLine; - lineLinter = new LineLinter(source, config, _rules, tokensByLine); + lineLinter = new LineLinter(source, config, _rules, tokensByLine, literate); lineErrors = lineLinter.lint(); errors = errors.concat(lineErrors); block_config = lineLinter.block_config; } else { block_config = { @@ -511,11 +512,11 @@ } return errors; }; -},{"./../package.json":1,"./ast_linter.coffee":2,"./lexical_linter.coffee":5,"./line_linter.coffee":6,"./rules.coffee":7,"./rules/arrow_spacing.coffee":8,"./rules/camel_case_classes.coffee":9,"./rules/colon_assignment_spacing.coffee":10,"./rules/cyclomatic_complexity.coffee":11,"./rules/duplicate_key.coffee":12,"./rules/empty_constructor_needs_parens.coffee":13,"./rules/indentation.coffee":14,"./rules/line_endings.coffee":15,"./rules/max_line_length.coffee":16,"./rules/missing_fat_arrows.coffee":17,"./rules/newlines_after_classes.coffee":18,"./rules/no_backticks.coffee":19,"./rules/no_empty_param_list.coffee":20,"./rules/no_implicit_braces.coffee":21,"./rules/no_implicit_parens.coffee":22,"./rules/no_plusplus.coffee":23,"./rules/no_stand_alone_at.coffee":24,"./rules/no_tabs.coffee":25,"./rules/no_throwing_strings.coffee":26,"./rules/no_trailing_semicolons.coffee":27,"./rules/no_trailing_whitespace.coffee":28,"./rules/no_unnecessary_fat_arrows.coffee":29,"./rules/non_empty_constructor_needs_parens.coffee":30,"./rules/space_operators.coffee":31}],5:[function(require,module,exports){ +},{"./../package.json":1,"./ast_linter.coffee":2,"./lexical_linter.coffee":5,"./line_linter.coffee":6,"./rules.coffee":7,"./rules/arrow_spacing.coffee":8,"./rules/camel_case_classes.coffee":9,"./rules/colon_assignment_spacing.coffee":10,"./rules/cyclomatic_complexity.coffee":11,"./rules/duplicate_key.coffee":12,"./rules/empty_constructor_needs_parens.coffee":13,"./rules/indentation.coffee":14,"./rules/line_endings.coffee":15,"./rules/max_line_length.coffee":16,"./rules/missing_fat_arrows.coffee":17,"./rules/newlines_after_classes.coffee":18,"./rules/no_backticks.coffee":19,"./rules/no_empty_param_list.coffee":20,"./rules/no_implicit_braces.coffee":21,"./rules/no_implicit_parens.coffee":22,"./rules/no_plusplus.coffee":23,"./rules/no_stand_alone_at.coffee":24,"./rules/no_tabs.coffee":25,"./rules/no_throwing_strings.coffee":26,"./rules/no_trailing_semicolons.coffee":27,"./rules/no_trailing_whitespace.coffee":28,"./rules/no_unnecessary_fat_arrows.coffee":29,"./rules/non_empty_constructor_needs_parens.coffee":30,"./rules/space_operators.coffee":31}],5:[function(_dereq_,module,exports){ var BaseLinter, LexicalLinter, TokenApi, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; @@ -539,11 +540,11 @@ return TokenApi; })(); -BaseLinter = require('./base_linter.coffee'); +BaseLinter = _dereq_('./base_linter.coffee'); module.exports = LexicalLinter = (function(_super) { __extends(LexicalLinter, _super); function LexicalLinter(source, config, rules, CoffeeScript) { @@ -615,19 +616,20 @@ return LexicalLinter; })(BaseLinter); -},{"./base_linter.coffee":3}],6:[function(require,module,exports){ +},{"./base_linter.coffee":3}],6:[function(_dereq_,module,exports){ var BaseLinter, LineApi, LineLinter, configStatement, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; LineApi = (function() { - function LineApi(source, config, tokensByLine) { + function LineApi(source, config, tokensByLine, literate) { this.config = config; this.tokensByLine = tokensByLine; + this.literate = literate; this.line = null; this.lines = source.split('\n'); this.lineCount = this.lines.length; this.context = { "class": { @@ -638,10 +640,14 @@ }; } LineApi.prototype.lineNumber = 0; + LineApi.prototype.isLiterate = function() { + return this.literate; + }; + LineApi.prototype.maintainClassContext = function(line) { if (this.context["class"].inClass) { if (this.lineHasToken('INDENT')) { this.context["class"].classIndents++; } else if (this.lineHasToken('OUTDENT')) { @@ -703,22 +709,25 @@ return LineApi; })(); -BaseLinter = require('./base_linter.coffee'); +BaseLinter = _dereq_('./base_linter.coffee'); configStatement = /coffeelint:\s*(disable|enable)(?:=([\w\s,]*))?/; module.exports = LineLinter = (function(_super) { __extends(LineLinter, _super); LineLinter.configStatement = configStatement; - function LineLinter(source, config, rules, tokensByLine) { + function LineLinter(source, config, rules, tokensByLine, literate) { + if (literate == null) { + literate = false; + } LineLinter.__super__.constructor.call(this, source, config, rules); - this.lineApi = new LineApi(source, config, tokensByLine); + this.lineApi = new LineApi(source, config, tokensByLine, literate); this.block_config = { enable: {}, disable: {} }; } @@ -790,11 +799,11 @@ return LineLinter; })(BaseLinter); -},{"./base_linter.coffee":3}],7:[function(require,module,exports){ +},{"./base_linter.coffee":3}],7:[function(_dereq_,module,exports){ var ERROR, IGNORE, WARN; ERROR = 'error'; WARN = 'warn'; @@ -807,11 +816,11 @@ message: '' } }; -},{}],8:[function(require,module,exports){ +},{}],8:[function(_dereq_,module,exports){ var ArrowSpacing; module.exports = ArrowSpacing = (function() { function ArrowSpacing() {} @@ -850,11 +859,11 @@ return ArrowSpacing; })(); -},{}],9:[function(require,module,exports){ +},{}],9:[function(_dereq_,module,exports){ var CamelCaseClasses, regexes; regexes = { camelCase: /^[A-Z][a-zA-Z\d]*$/ }; @@ -897,11 +906,11 @@ return CamelCaseClasses; })(); -},{}],10:[function(require,module,exports){ +},{}],10:[function(_dereq_,module,exports){ var ColonAssignmentSpacing; module.exports = ColonAssignmentSpacing = (function() { function ColonAssignmentSpacing() {} @@ -951,11 +960,11 @@ return ColonAssignmentSpacing; })(); -},{}],11:[function(require,module,exports){ +},{}],11:[function(_dereq_,module,exports){ var NoTabs; module.exports = NoTabs = (function() { function NoTabs() {} @@ -979,21 +988,22 @@ this.lintNode(node); return void 0; }; NoTabs.prototype.lintNode = function(node, line) { - var complexity, error, name, rule, - _this = this; + var complexity, error, name, rule; name = node.constructor.name; complexity = this.getComplexity(node); - node.eachChild(function(childNode) { - var nodeLine; - nodeLine = childNode.locationData.first_line; - if (childNode) { - return complexity += _this.lintNode(childNode, nodeLine); - } - }); + node.eachChild((function(_this) { + return function(childNode) { + var nodeLine; + nodeLine = childNode.locationData.first_line; + if (childNode) { + return complexity += _this.lintNode(childNode, nodeLine); + } + }; + })(this)); rule = this.astApi.config[this.rule.name]; if (name === 'Code' && complexity >= rule.value) { error = this.astApi.createError({ context: complexity + 1, lineNumber: line + 1, @@ -1009,11 +1019,11 @@ return NoTabs; })(); -},{}],12:[function(require,module,exports){ +},{}],12:[function(_dereq_,module,exports){ var DuplicateKey; module.exports = DuplicateKey = (function() { DuplicateKey.prototype.rule = { name: 'duplicate_key', @@ -1078,11 +1088,11 @@ return DuplicateKey; })(); -},{}],13:[function(require,module,exports){ +},{}],13:[function(_dereq_,module,exports){ var EmptyConstructorNeedsParens; module.exports = EmptyConstructorNeedsParens = (function() { function EmptyConstructorNeedsParens() {} @@ -1125,11 +1135,11 @@ return EmptyConstructorNeedsParens; })(); -},{}],14:[function(require,module,exports){ +},{}],14:[function(_dereq_,module,exports){ var Indentation; module.exports = Indentation = (function() { Indentation.prototype.rule = { name: 'indentation', @@ -1231,11 +1241,11 @@ return Indentation; })(); -},{}],15:[function(require,module,exports){ +},{}],15:[function(_dereq_,module,exports){ var LineEndings; module.exports = LineEndings = (function() { function LineEndings() {} @@ -1275,14 +1285,15 @@ return LineEndings; })(); -},{}],16:[function(require,module,exports){ +},{}],16:[function(_dereq_,module,exports){ var MaxLineLength, regexes; regexes = { + literateComment: /^\#\s/, longUrlComment: /^\s*\#\s*http[^\s]+$/ }; module.exports = MaxLineLength = (function() { function MaxLineLength() {} @@ -1295,31 +1306,35 @@ message: 'Line exceeds maximum allowed length', description: "This rule imposes a maximum line length on your code. <a\nhref=\"http://www.python.org/dev/peps/pep-0008/\">Python's style\nguide</a> does a good job explaining why you might want to limit the\nlength of your lines, though this is a matter of taste.\n\nLines can be no longer than eighty characters by default." }; MaxLineLength.prototype.lintLine = function(line, lineApi) { - var limitComments, max, _ref, _ref1; + var limitComments, lineLength, max, _ref, _ref1; max = (_ref = lineApi.config[this.rule.name]) != null ? _ref.value : void 0; limitComments = (_ref1 = lineApi.config[this.rule.name]) != null ? _ref1.limitComments : void 0; - if (max && max < line.length && !regexes.longUrlComment.test(line)) { + lineLength = line.length; + if (lineApi.isLiterate() && regexes.literateComment.test(line)) { + lineLength -= 2; + } + if (max && max < lineLength && !regexes.longUrlComment.test(line)) { if (!limitComments) { if (lineApi.getLineTokens().length === 0) { return; } } return { - context: "Length is " + line.length + ", max is " + max + context: "Length is " + lineLength + ", max is " + max }; } }; return MaxLineLength; })(); -},{}],17:[function(require,module,exports){ +},{}],17:[function(_dereq_,module,exports){ var MissingFatArrows, any, isClass, isCode, isFatArrowCode, isObject, isThis, isValue, methodsOfClass, needsFatArrow, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; isCode = function(node) { return (node != null ? node.constructor.name : void 0) === 'Code'; @@ -1384,52 +1399,53 @@ this.lintNode(node, astApi); return void 0; }; MissingFatArrows.prototype.lintNode = function(node, astApi, methods) { - var error, - _this = this; + var error; if (methods == null) { methods = []; } if ((!isFatArrowCode(node)) && (__indexOf.call(methods, node) < 0) && (needsFatArrow(node))) { error = astApi.createError({ lineNumber: node.locationData.first_line + 1 }); this.errors.push(error); } - return node.eachChild(function(child) { - return _this.lintNode(child, astApi, (function() { - switch (false) { - case !isClass(node): - return methodsOfClass(node); - case !isCode(node): - return []; - default: - return methods; - } - })()); - }); + return node.eachChild((function(_this) { + return function(child) { + return _this.lintNode(child, astApi, (function() { + switch (false) { + case !isClass(node): + return methodsOfClass(node); + case !isCode(node): + return []; + default: + return methods; + } + })()); + }; + })(this)); }; return MissingFatArrows; })(); -},{}],18:[function(require,module,exports){ +},{}],18:[function(_dereq_,module,exports){ var NewlinesAfterClasses; module.exports = NewlinesAfterClasses = (function() { function NewlinesAfterClasses() {} NewlinesAfterClasses.prototype.rule = { name: 'newlines_after_classes', value: 3, level: 'ignore', message: 'Wrong count of newlines between a class and other code', - description: "Checks the number of newlines between classes and other code" + description: "Checks the number of newlines between classes and other code" }; NewlinesAfterClasses.prototype.lintLine = function(line, lineApi) { var context, ending, got, lineNumber; ending = lineApi.config[this.rule.name].value; @@ -1449,11 +1465,11 @@ return NewlinesAfterClasses; })(); -},{}],19:[function(require,module,exports){ +},{}],19:[function(_dereq_,module,exports){ var NoBackticks; module.exports = NoBackticks = (function() { function NoBackticks() {} @@ -1473,11 +1489,11 @@ return NoBackticks; })(); -},{}],20:[function(require,module,exports){ +},{}],20:[function(_dereq_,module,exports){ var NoEmptyParamList; module.exports = NoEmptyParamList = (function() { function NoEmptyParamList() {} @@ -1499,11 +1515,11 @@ return NoEmptyParamList; })(); -},{}],21:[function(require,module,exports){ +},{}],21:[function(_dereq_,module,exports){ var NoImplicitBraces; module.exports = NoImplicitBraces = (function() { function NoImplicitBraces() {} @@ -1548,11 +1564,11 @@ return NoImplicitBraces; })(); -},{}],22:[function(require,module,exports){ +},{}],22:[function(_dereq_,module,exports){ var NoImplicitParens; module.exports = NoImplicitParens = (function() { function NoImplicitParens() {} @@ -1572,11 +1588,11 @@ return NoImplicitParens; })(); -},{}],23:[function(require,module,exports){ +},{}],23:[function(_dereq_,module,exports){ var NoPlusPlus; module.exports = NoPlusPlus = (function() { function NoPlusPlus() {} @@ -1598,11 +1614,11 @@ return NoPlusPlus; })(); -},{}],24:[function(require,module,exports){ +},{}],24:[function(_dereq_,module,exports){ var NoStandAloneAt; module.exports = NoStandAloneAt = (function() { function NoStandAloneAt() {} @@ -1634,11 +1650,11 @@ return NoStandAloneAt; })(); -},{}],25:[function(require,module,exports){ +},{}],25:[function(_dereq_,module,exports){ var NoTabs, indentationRegex, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; indentationRegex = /\S/; @@ -1665,11 +1681,11 @@ return NoTabs; })(); -},{}],26:[function(require,module,exports){ +},{}],26:[function(_dereq_,module,exports){ var NoThrowingStrings; module.exports = NoThrowingStrings = (function() { function NoThrowingStrings() {} @@ -1692,11 +1708,11 @@ return NoThrowingStrings; })(); -},{}],27:[function(require,module,exports){ +},{}],27:[function(_dereq_,module,exports){ var NoTrailingSemicolons, regexes, __slice = [].slice; regexes = { trailingSemicolon: /;\r?$/ @@ -1711,17 +1727,29 @@ message: 'Line contains a trailing semicolon', description: "This rule prohibits trailing semicolons, since they are needless\ncruft in CoffeeScript.\n<pre>\n<code># This semicolon is meaningful.\nx = '1234'; console.log(x)\n\n# This semicolon is redundant.\nalert('end of line');\n</code>\n</pre>\nTrailing semicolons are forbidden by default." }; NoTrailingSemicolons.prototype.lintLine = function(line, lineApi) { - var first, hasNewLine, hasSemicolon, last, lineTokens, _i, _ref; + var endPos, first, hasNewLine, hasSemicolon, last, lineTokens, newLine, startCounter, startPos, _i, _ref; lineTokens = lineApi.getLineTokens(); - if (lineTokens.length === 1 && lineTokens[0][0] === 'TERMINATOR') { + if (lineTokens.length === 1 && ((_ref = lineTokens[0][0]) === 'TERMINATOR' || _ref === 'HERECOMMENT')) { return; } - hasSemicolon = regexes.trailingSemicolon.test(line); - _ref = lineApi.getLineTokens(), first = 2 <= _ref.length ? __slice.call(_ref, 0, _i = _ref.length - 1) : (_i = 0, []), last = _ref[_i++]; + newLine = line; + if (lineTokens.length > 1 && lineTokens[lineTokens.length - 1][0] === 'TERMINATOR') { + startPos = lineTokens[lineTokens.length - 2][2].last_column + 1; + endPos = lineTokens[lineTokens.length - 1][2].first_column; + if (startPos !== endPos) { + startCounter = startPos; + while (line[startCounter] !== "#" && startCounter < line.length) { + startCounter++; + } + newLine = line.substring(0, startCounter).replace(/\s*$/, ''); + } + } + hasSemicolon = regexes.trailingSemicolon.test(newLine); + first = 2 <= lineTokens.length ? __slice.call(lineTokens, 0, _i = lineTokens.length - 1) : (_i = 0, []), last = lineTokens[_i++]; hasNewLine = last && (last.newLine != null); if (hasSemicolon && !hasNewLine && lineApi.lineHasToken() && last[0] !== 'STRING') { return true; } }; @@ -1729,16 +1757,16 @@ return NoTrailingSemicolons; })(); -},{}],28:[function(require,module,exports){ +},{}],28:[function(_dereq_,module,exports){ var NoTrailingWhitespace, regexes; regexes = { trailingWhitespace: /[^\s]+[\t ]+\r?$/, - onlySpaces: /^[\t\s]+\r?$/, + onlySpaces: /^[\t ]+\r?$/, lineHasComment: /^\s*[^\#]*\#/ }; module.exports = NoTrailingWhitespace = (function() { function NoTrailingWhitespace() {} @@ -1792,11 +1820,11 @@ return NoTrailingWhitespace; })(); -},{}],29:[function(require,module,exports){ +},{}],29:[function(_dereq_,module,exports){ var NoUnnecessaryFatArrows, any, isCode, isFatArrowCode, isThis, needsFatArrow; isCode = function(node) { return node.constructor.name === 'Code'; }; @@ -1837,41 +1865,41 @@ this.lintNode(node, astApi); return void 0; }; NoUnnecessaryFatArrows.prototype.lintNode = function(node, astApi) { - var error, - _this = this; + var error; if ((isFatArrowCode(node)) && (!needsFatArrow(node))) { error = astApi.createError({ lineNumber: node.locationData.first_line + 1 }); this.errors.push(error); } - return node.eachChild(function(child) { - return _this.lintNode(child, astApi); - }); + return node.eachChild((function(_this) { + return function(child) { + return _this.lintNode(child, astApi); + }; + })(this)); }; return NoUnnecessaryFatArrows; })(); -},{}],30:[function(require,module,exports){ -var NonEmptyConstructorNeedsParens, ParentClass, _ref, +},{}],30:[function(_dereq_,module,exports){ +var NonEmptyConstructorNeedsParens, ParentClass, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; -ParentClass = require('./empty_constructor_needs_parens.coffee'); +ParentClass = _dereq_('./empty_constructor_needs_parens.coffee'); module.exports = NonEmptyConstructorNeedsParens = (function(_super) { __extends(NonEmptyConstructorNeedsParens, _super); function NonEmptyConstructorNeedsParens() { - _ref = NonEmptyConstructorNeedsParens.__super__.constructor.apply(this, arguments); - return _ref; + return NonEmptyConstructorNeedsParens.__super__.constructor.apply(this, arguments); } NonEmptyConstructorNeedsParens.prototype.rule = { name: 'non_empty_constructor_needs_parens', level: 'ignore', @@ -1888,11 +1916,11 @@ return NonEmptyConstructorNeedsParens; })(ParentClass); -},{"./empty_constructor_needs_parens.coffee":13}],31:[function(require,module,exports){ +},{"./empty_constructor_needs_parens.coffee":13}],31:[function(_dereq_,module,exports){ var SpaceOperators, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; module.exports = SpaceOperators = (function() { SpaceOperators.prototype.rule = { @@ -1900,11 +1928,11 @@ level: 'ignore', message: 'Operators must be spaced properly', description: "This rule enforces that operators have space around them." }; - SpaceOperators.prototype.tokens = ["+", "-", "=", "MATH", "COMPARE", "LOGIC", "COMPOUND_ASSIGN", "(", ")", "CALL_START", "CALL_END"]; + SpaceOperators.prototype.tokens = ["+", "-", "=", "**", "MATH", "COMPARE", "LOGIC", "COMPOUND_ASSIGN", "(", ")", "CALL_START", "CALL_END"]; function SpaceOperators() { this.callTokens = []; this.parenTokens = []; } @@ -2008,8 +2036,8 @@ return SpaceOperators; })(); -},{}]},{},[4])(4) -}); -; +},{}]},{},[4]) +(4) +}); \ No newline at end of file