coffeelint/lib/coffeelint.js in coffeelint-1.14.0 vs coffeelint/lib/coffeelint.js in coffeelint-1.16.0

- old
+ new

@@ -1,14 +1,286 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.coffeelint = f()}})(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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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){ +module.exports={ + "name": "coffeelint", + "description": "Lint your CoffeeScript", + "version": "1.16.0", + "homepage": "http://www.coffeelint.org", + "keywords": [ + "lint", + "coffeescript", + "coffee-script" + ], + "author": "Matthew Perpick <clutchski@gmail.com>", + "main": "./lib/coffeelint.js", + "engines": { + "npm": ">=1.3.7", + "node": ">=0.8.0" + }, + "repository": { + "type": "git", + "url": "git://github.com/clutchski/coffeelint.git" + }, + "bin": { + "coffeelint": "./bin/coffeelint" + }, + "dependencies": { + "browserify": "^13.1.0", + "coffee-script": "~1.11.0", + "coffeeify": "~1.0.0", + "glob": "^7.0.6", + "ignore": "^3.0.9", + "optimist": "^0.6.1", + "resolve": "^0.6.3", + "strip-json-comments": "^1.0.2" + }, + "devDependencies": { + "vows": ">=0.8.1", + "underscore": ">=1.4.4" + }, + "license": "MIT", + "scripts": { + "pretest": "cake compile", + "test": "./vowsrunner.js --spec test/*.coffee test/*.litcoffee", + "testrule": "npm run compile && ./vowsrunner.js --spec", + "posttest": "npm run lint", + "prepublish": "cake prepublish", + "postpublish": "cake postpublish", + "publish": "cake publish", + "install": "cake install", + "lint": "cake compile && ./bin/coffeelint .", + "lint-csv": "cake compile && ./bin/coffeelint --csv .", + "lint-jslint": "cake compile && ./bin/coffeelint --jslint .", + "compile": "cake compile" + } +} +},{}],2:[function(require,module,exports){ +var ASTApi, ASTLinter, BaseLinter, hasChildren, node_children, + hasProp = {}.hasOwnProperty, + extend = 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'); + +node_children = { + Class: ['variable', 'parent', 'body'], + Code: ['params', 'body'], + For: ['body', 'source', 'guard', 'step'], + If: ['condition', 'body', 'elseBody'], + Obj: ['properties'], + Op: ['first', 'second'], + Switch: ['subject', 'cases', 'otherwise'], + Try: ['attempt', 'recovery', 'ensure'], + Value: ['base', 'properties'], + While: ['condition', 'guard', 'body'] +}; + +hasChildren = function(node, children) { + var ref; + return (node != null ? (ref = node.children) != null ? ref.length : void 0 : void 0) === children.length && (node != null ? node.children.every(function(elem, i) { + return elem === children[i]; + }) : void 0); +}; + +ASTApi = (function() { + function ASTApi(config1) { + this.config = config1; + } + + ASTApi.prototype.getNodeName = function(node) { + var children, name, ref; + name = node != null ? (ref = node.constructor) != null ? ref.name : void 0 : void 0; + if (node_children[name]) { + return name; + } else { + for (name in node_children) { + if (!hasProp.call(node_children, name)) continue; + children = node_children[name]; + if (hasChildren(node, children)) { + return name; + } + } + } + }; + + return ASTApi; + +})(); + +module.exports = ASTLinter = (function(superClass) { + extend(ASTLinter, superClass); + + function ASTLinter(source, config, rules, CoffeeScript) { + this.CoffeeScript = CoffeeScript; + ASTLinter.__super__.constructor.call(this, source, config, rules); + this.astApi = new ASTApi(this.config); + } + + ASTLinter.prototype.acceptRule = function(rule) { + return typeof rule.lintAST === 'function'; + }; + + ASTLinter.prototype.lint = function() { + var coffeeError, err, errors, j, len, ref, rule, v; + errors = []; + try { + this.node = this.CoffeeScript.nodes(this.source); + } catch (error) { + coffeeError = error; + err = this._parseCoffeeScriptError(coffeeError); + if (err != null) { + errors.push(err); + } + return errors; + } + ref = this.rules; + for (j = 0, len = ref.length; j < len; j++) { + rule = ref[j]; + 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; + } + } + return errors; + }; + + ASTLinter.prototype._parseCoffeeScriptError = function(coffeeError) { + var attrs, lineNumber, match, message, rule; + rule = this.config['coffeescript_error']; + message = coffeeError.toString(); + lineNumber = -1; + if (coffeeError.location != null) { + lineNumber = coffeeError.location.first_line + 1; + } else { + match = /line (\d+)/.exec(message); + if ((match != null ? match.length : void 0) > 1) { + lineNumber = parseInt(match[1], 10); + } + } + attrs = { + message: message, + level: rule.level, + lineNumber: lineNumber + }; + return this.createError('coffeescript_error', attrs); + }; + + return ASTLinter; + +})(BaseLinter); + + +},{"./base_linter.coffee":3}],3:[function(require,module,exports){ +var BaseLinter, defaults, extend, + slice = [].slice; + +extend = function() { + var destination, i, k, len, source, sources, v; + destination = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : []; + for (i = 0, len = sources.length; i < len; i++) { + source = sources[i]; + for (k in source) { + v = source[k]; + destination[k] = v; + } + } + return destination; +}; + +defaults = function(source, defaults) { + return extend({}, defaults, source); +}; + +module.exports = BaseLinter = (function() { + function BaseLinter(source1, config, rules) { + this.source = source1; + this.config = config; + this.setupRules(rules); + } + + BaseLinter.prototype.isObject = function(obj) { + return obj === Object(obj); + }; + + BaseLinter.prototype.createError = function(ruleName, attrs) { + var level; + if (attrs == null) { + attrs = {}; + } + if (attrs.level == null) { + attrs.level = this.config[ruleName].level; + } + level = attrs.level; + if (level !== 'ignore' && level !== 'warn' && level !== 'error') { + throw new Error("unknown level " + level + " for rule: " + ruleName); + } + if (level === 'error' || level === 'warn') { + attrs.rule = ruleName; + return defaults(attrs, this.config[ruleName]); + } else { + return null; + } + }; + + BaseLinter.prototype.acceptRule = function(rule) { + throw new Error('acceptRule needs to be overridden in the subclass'); + }; + + BaseLinter.prototype.setupRules = function(rules) { + var RuleConstructor, level, name, results, rule; + this.rules = []; + results = []; + for (name in rules) { + RuleConstructor = rules[name]; + level = this.config[name].level; + if (level === 'error' || level === 'warn') { + rule = new RuleConstructor(this, this.config); + if (this.acceptRule(rule)) { + results.push(this.rules.push(rule)); + } else { + results.push(void 0); + } + } else if (level !== 'ignore') { + throw new Error("unknown level " + level + " for rule: " + rule); + } else { + results.push(void 0); + } + } + return results; + }; + + BaseLinter.prototype.normalizeResult = function(p, result) { + if (result === true) { + return this.createError(p.rule.name); + } + if (this.isObject(result)) { + return this.createError(p.rule.name, result); + } + }; + + return BaseLinter; + +})(); + + +},{}],4:[function(require,module,exports){ + /* CoffeeLint Copyright (c) 2011 Matthew Perpick. CoffeeLint is freely distributable under the MIT license. */ -var ASTLinter, CoffeeScript, ERROR, ErrorReport, IGNORE, LexicalLinter, LineLinter, RULES, WARN, _rules, cache, coffeelint, defaults, difference, extend, hasSyntaxError, mergeDefaultConfig, nodeRequire, packageJSON, sameJSON, +var ASTLinter, CoffeeScript, ERROR, ErrorReport, IGNORE, LexicalLinter, LineLinter, RULES, WARN, _rules, cache, coffeelint, defaults, difference, extend, hasSyntaxError, mergeDefaultConfig, nodeRequire, packageJSON, sameJSON, union, 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; @@ -37,14 +309,14 @@ IGNORE = 'ignore'; coffeelint.RULES = RULES = require('./rules.coffee'); extend = function() { - var destination, k, len, n, source, sources, v; + var destination, j, k, len, source, sources, v; destination = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : []; - for (n = 0, len = sources.length; n < len; n++) { - source = sources[n]; + for (j = 0, len = sources.length; j < len; j++) { + source = sources[j]; for (k in source) { v = source[k]; destination[k] = v; } } @@ -53,19 +325,35 @@ defaults = function(source, defaults) { return extend({}, defaults, source); }; +union = function(a, b) { + var c, j, len, len1, n, results, x; + c = {}; + for (j = 0, len = a.length; j < len; j++) { + x = a[j]; + c[x] = true; + } + for (n = 0, len1 = b.length; n < len1; n++) { + x = b[n]; + c[x] = true; + } + results = []; + for (x in c) { + results.push(x); + } + return results; +}; + difference = function(a, b) { - var j, ref, results; - j = 0; + var j, len, results, x; results = []; - while (j < a.length) { - if (ref = a[j], indexOf.call(b, ref) >= 0) { - results.push(a.splice(j, 1)); - } else { - results.push(j++); + for (j = 0, len = a.length; j < len; j++) { + x = a[j]; + if (indexOf.call(b, x) < 0) { + results.push(x); } } return results; }; @@ -80,11 +368,11 @@ mergeDefaultConfig = function(userConfig) { var config, rule, ruleConfig, ruleLoader; try { ruleLoader = nodeRequire('./ruleLoader'); ruleLoader.loadFromConfig(coffeelint, userConfig); - } catch (undefined) {} + } catch (error) {} config = {}; if (userConfig.coffeelint) { config.coffeelint = userConfig.coffeelint; } for (rule in RULES) { @@ -137,20 +425,20 @@ } return newConfig; }; coffeelint.invertLiterate = function(source) { - var len, line, n, newSource, ref; + var j, len, line, newSource, ref; source = CoffeeScript.helpers.invertLiterate(source); newSource = ''; ref = source.split('\n'); - for (n = 0, len = ref.length; n < len; n++) { - line = ref[n]; + for (j = 0, len = ref.length; j < len; j++) { + line = ref[j]; if (line.match(/^#/)) { line = line.replace(/\s*$/, ''); } - line = line.replace(/^\s{4}/g, ''); + line = line.replace(/^[ ]{4}|^\t/g, ''); newSource += line + "\n"; } return newSource; }; @@ -194,15 +482,15 @@ RULES[p.rule.name] = p.rule; return _rules[p.rule.name] = RuleConstructor; }; coffeelint.getRules = function() { - var key, len, n, output, ref; + var j, key, len, output, ref; output = {}; ref = Object.keys(RULES).sort(); - for (n = 0, len = ref.length; n < len; n++) { - key = ref[n]; + for (j = 0, len = ref.length; j < len; j++) { + key = ref[j]; output[key] = RULES[key]; } return output; }; @@ -282,22 +570,22 @@ hasSyntaxError = function(source) { try { CoffeeScript.tokens(source); return false; - } catch (undefined) {} + } catch (error) {} return true; }; ErrorReport = require('./error_report.coffee'); coffeelint.getErrorReport = function() { return new ErrorReport(coffeelint); }; coffeelint.lint = function(source, userConfig, literate) { - var all_errors, astErrors, block_config, cmd, config, disabled, disabled_initially, e, errors, i, l, len, len1, len2, lexErrors, lexicalLinter, lineErrors, lineLinter, m, n, name, next_line, o, q, r, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ruleLoader, rules, s, sourceLength, t, tokensByLine, transform; + var allErrors, astErrors, cmd, config, disabled, disabledEntirely, disabledInitially, disabledLine, e, errors, i, inlineConfig, j, l, len, len1, lexErrors, lexicalLinter, lineErrors, lineLinter, m, n, name, nextLine, o, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, regex, rule, ruleLoader, rules, set, sourceLength, tokensByLine, transform; if (userConfig == null) { userConfig = {}; } if (literate == null) { literate = false; @@ -314,17 +602,17 @@ source = this.invertLiterate(source); } if ((userConfig != null ? (ref = userConfig.coffeelint) != null ? ref.transforms : void 0 : void 0) != null) { sourceLength = source.split('\n').length; ref2 = userConfig != null ? (ref1 = userConfig.coffeelint) != null ? ref1.transforms : void 0 : void 0; - for (n = 0, len = ref2.length; n < len; n++) { - m = ref2[n]; + for (j = 0, len = ref2.length; j < len; j++) { + m = ref2[j]; try { ruleLoader = nodeRequire('./ruleLoader'); transform = ruleLoader.require(m); source = transform(source); - } catch (undefined) {} + } catch (error) {} } if (sourceLength !== source.split('\n').length && config.transform_messes_up_line_numbers.level !== 'ignore') { errors.push(extend({ lineNumber: 1, context: "File was transformed from " + sourceLength + " lines to " + (source.split("\n").length) + " lines" @@ -339,28 +627,18 @@ if (_rules[name] == null) { void 0; } } } - disabled_initially = []; + disabledInitially = []; ref4 = source.split('\n'); - for (o = 0, len1 = ref4.length; o < len1; o++) { - l = ref4[o]; - s = LineLinter.configStatement.exec(l); - if ((s != null ? s.length : void 0) > 2 && indexOf.call(s, 'enable') >= 0) { - ref5 = s.slice(1); - for (q = 0, len2 = ref5.length; q < len2; q++) { - r = ref5[q]; - if (r !== 'enable' && r !== 'disable') { - if (!(r in config && ((ref6 = config[r].level) === 'warn' || ref6 === 'error'))) { - disabled_initially.push(r); - config[r] = { - level: 'error' - }; - } - } - } + for (n = 0, len1 = ref4.length; n < len1; n++) { + l = ref4[n]; + ref5 = LineLinter.getDirective(l) || [], regex = ref5[0], set = ref5[1], rule = ref5[ref5.length - 1]; + if ((set === 'enable' || set === 'enable-line') && ((ref6 = config[rule]) != null ? ref6.level : void 0) === 'ignore') { + disabledInitially.push(rule); + config[rule].level = 'error'; } } astErrors = new ASTLinter(source, config, _rules, CoffeeScript).lint(); errors = errors.concat(astErrors); if (!hasSyntaxError(source)) { @@ -369,47 +647,85 @@ errors = errors.concat(lexErrors); tokensByLine = lexicalLinter.tokensByLine; lineLinter = new LineLinter(source, config, _rules, tokensByLine, literate); lineErrors = lineLinter.lint(); errors = errors.concat(lineErrors); - block_config = lineLinter.block_config; + inlineConfig = lineLinter.inlineConfig; } else { - block_config = { + inlineConfig = { enable: {}, - disable: {} + disable: {}, + 'enable-line': {}, + 'disable-line': {} }; } errors.sort(function(a, b) { return a.lineNumber - b.lineNumber; }); - all_errors = errors; + disabledEntirely = (function() { + var len2, map, o, ref7, result; + result = []; + map = {}; + ref7 = errors || []; + for (o = 0, len2 = ref7.length; o < len2; o++) { + name = ref7[o].name; + if (!map[name]) { + result.push(name); + map[name] = true; + } + } + return result; + })(); + allErrors = errors; errors = []; - disabled = disabled_initially; - next_line = 0; - for (i = t = 0, ref7 = source.split('\n').length; 0 <= ref7 ? t < ref7 : t > ref7; i = 0 <= ref7 ? ++t : --t) { - for (cmd in block_config) { - rules = block_config[cmd][i]; + disabled = disabledInitially; + nextLine = 0; + for (i = o = 0, ref7 = source.split('\n').length; 0 <= ref7 ? o < ref7 : o > ref7; i = 0 <= ref7 ? ++o : --o) { + disabledLine = disabled; + for (cmd in inlineConfig) { + rules = inlineConfig[cmd][i]; if (rules != null) { ({ 'disable': function() { - return disabled = disabled.concat(rules); + if (rules.length) { + disabled = union(disabled, rules); + return disabledLine = union(disabledLine, rules); + } else { + return disabled = disabledLine = disabledEntirely; + } }, + 'disable-line': function() { + if (rules.length) { + return disabledLine = union(disabledLine, rules); + } else { + return disabledLine = disabledEntirely; + } + }, 'enable': function() { - difference(disabled, rules); - if (rules.length === 0) { - return disabled = disabled_initially; + if (rules.length) { + disabled = difference(disabled, rules); + return disabledLine = difference(disabledLine, rules); + } else { + return disabled = disabledLine = disabledInitially; } + }, + 'enable-line': function() { + if (rules.length) { + return disabledLine = difference(disabledLine, rules); + } else { + return disabledLine = disabledInitially; + } } })[cmd](); } } - while (next_line === i && all_errors.length > 0) { - next_line = all_errors[0].lineNumber - 1; - e = all_errors[0]; + while (nextLine === i && allErrors.length > 0) { + nextLine = allErrors[0].lineNumber - 1; + e = allErrors[0]; if (e.lineNumber === i + 1 || (e.lineNumber == null)) { - e = all_errors.shift(); - if (ref8 = e.rule, indexOf.call(disabled, ref8) < 0) { + e = allErrors.shift(); + if (ref8 = e.rule, indexOf.call(disabledLine, ref8) < 0) { errors.push(e); } } } } @@ -422,286 +738,11 @@ coffeelint.setCache = function(obj) { return cache = obj; }; - -},{"./../package.json":2,"./ast_linter.coffee":3,"./error_report.coffee":5,"./lexical_linter.coffee":6,"./line_linter.coffee":7,"./rules.coffee":8,"./rules/arrow_spacing.coffee":9,"./rules/braces_spacing.coffee":10,"./rules/camel_case_classes.coffee":11,"./rules/colon_assignment_spacing.coffee":12,"./rules/cyclomatic_complexity.coffee":13,"./rules/duplicate_key.coffee":14,"./rules/empty_constructor_needs_parens.coffee":15,"./rules/ensure_comprehensions.coffee":16,"./rules/eol_last.coffee":17,"./rules/indentation.coffee":18,"./rules/line_endings.coffee":19,"./rules/max_line_length.coffee":20,"./rules/missing_fat_arrows.coffee":21,"./rules/newlines_after_classes.coffee":22,"./rules/no_backticks.coffee":23,"./rules/no_debugger.coffee":24,"./rules/no_empty_functions.coffee":25,"./rules/no_empty_param_list.coffee":26,"./rules/no_implicit_braces.coffee":27,"./rules/no_implicit_parens.coffee":28,"./rules/no_interpolation_in_single_quotes.coffee":29,"./rules/no_nested_string_interpolation.coffee":30,"./rules/no_plusplus.coffee":31,"./rules/no_private_function_fat_arrows.coffee":32,"./rules/no_stand_alone_at.coffee":33,"./rules/no_tabs.coffee":34,"./rules/no_this.coffee":35,"./rules/no_throwing_strings.coffee":36,"./rules/no_trailing_semicolons.coffee":37,"./rules/no_trailing_whitespace.coffee":38,"./rules/no_unnecessary_double_quotes.coffee":39,"./rules/no_unnecessary_fat_arrows.coffee":40,"./rules/non_empty_constructor_needs_parens.coffee":41,"./rules/prefer_english_operator.coffee":42,"./rules/space_operators.coffee":43,"./rules/spacing_after_comma.coffee":44,"./rules/transform_messes_up_line_numbers.coffee":45}],2:[function(require,module,exports){ -module.exports={ - "name": "coffeelint", - "description": "Lint your CoffeeScript", - "version": "1.14.0", - "homepage": "http://www.coffeelint.org", - "keywords": [ - "lint", - "coffeescript", - "coffee-script" - ], - "author": "Matthew Perpick <clutchski@gmail.com>", - "main": "./lib/coffeelint.js", - "engines": { - "npm": ">=1.3.7", - "node": ">=0.8.0" - }, - "repository": { - "type": "git", - "url": "git://github.com/clutchski/coffeelint.git" - }, - "bin": { - "coffeelint": "./bin/coffeelint" - }, - "dependencies": { - "browserify": "~8.1.0", - "coffee-script": "^1.9.1", - "coffeeify": "~1.0.0", - "glob": "^4.0.0", - "ignore": "^2.2.15", - "optimist": "^0.6.1", - "resolve": "^0.6.3", - "strip-json-comments": "^1.0.2" - }, - "devDependencies": { - "vows": ">=0.6.0", - "underscore": ">=1.4.4" - }, - "license": "MIT", - "scripts": { - "pretest": "cake compile", - "test": "./vowsrunner.js --spec test/*.coffee test/*.litcoffee", - "testrule": "npm run compile && ./vowsrunner.js --spec", - "posttest": "npm run lint", - "prepublish": "cake prepublish", - "postpublish": "cake postpublish", - "publish": "cake publish", - "install": "cake install", - "lint": "cake compile && ./bin/coffeelint .", - "lint-csv": "cake compile && ./bin/coffeelint --csv .", - "lint-jslint": "cake compile && ./bin/coffeelint --jslint .", - "compile": "cake compile" - } -} - -},{}],3:[function(require,module,exports){ -var ASTApi, ASTLinter, BaseLinter, hasChildren, node_children, - hasProp = {}.hasOwnProperty, - extend = 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'); - -node_children = { - Class: ['variable', 'parent', 'body'], - Code: ['params', 'body'], - For: ['body', 'source', 'guard', 'step'], - If: ['condition', 'body', 'elseBody'], - Obj: ['properties'], - Op: ['first', 'second'], - Switch: ['subject', 'cases', 'otherwise'], - Try: ['attempt', 'recovery', 'ensure'], - Value: ['base', 'properties'], - While: ['condition', 'guard', 'body'] -}; - -hasChildren = function(node, children) { - var ref; - return (node != null ? (ref = node.children) != null ? ref.length : void 0 : void 0) === children.length && (node != null ? node.children.every(function(elem, i) { - return elem === children[i]; - }) : void 0); -}; - -ASTApi = (function() { - function ASTApi(config1) { - this.config = config1; - } - - ASTApi.prototype.getNodeName = function(node) { - var children, name, ref; - name = node != null ? (ref = node.constructor) != null ? ref.name : void 0 : void 0; - if (node_children[name]) { - return name; - } else { - for (name in node_children) { - if (!hasProp.call(node_children, name)) continue; - children = node_children[name]; - if (hasChildren(node, children)) { - return name; - } - } - } - }; - - return ASTApi; - -})(); - -module.exports = ASTLinter = (function(superClass) { - extend(ASTLinter, superClass); - - function ASTLinter(source, config, rules, CoffeeScript) { - this.CoffeeScript = CoffeeScript; - ASTLinter.__super__.constructor.call(this, source, config, rules); - this.astApi = new ASTApi(this.config); - } - - ASTLinter.prototype.acceptRule = function(rule) { - return typeof rule.lintAST === 'function'; - }; - - ASTLinter.prototype.lint = function() { - var coffeeError, err, error, errors, j, len, ref, rule, v; - errors = []; - try { - this.node = this.CoffeeScript.nodes(this.source); - } catch (error) { - coffeeError = error; - err = this._parseCoffeeScriptError(coffeeError); - if (err != null) { - errors.push(err); - } - return errors; - } - ref = this.rules; - for (j = 0, len = ref.length; j < len; j++) { - rule = ref[j]; - 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; - } - } - return errors; - }; - - ASTLinter.prototype._parseCoffeeScriptError = function(coffeeError) { - var attrs, lineNumber, match, message, rule; - rule = this.config['coffeescript_error']; - message = coffeeError.toString(); - lineNumber = -1; - if (coffeeError.location != null) { - lineNumber = coffeeError.location.first_line + 1; - } else { - match = /line (\d+)/.exec(message); - if ((match != null ? match.length : void 0) > 1) { - lineNumber = parseInt(match[1], 10); - } - } - attrs = { - message: message, - level: rule.level, - lineNumber: lineNumber - }; - return this.createError('coffeescript_error', attrs); - }; - - return ASTLinter; - -})(BaseLinter); - - - -},{"./base_linter.coffee":4}],4:[function(require,module,exports){ -var BaseLinter, defaults, extend, - slice = [].slice; - -extend = function() { - var destination, i, k, len, source, sources, v; - destination = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : []; - for (i = 0, len = sources.length; i < len; i++) { - source = sources[i]; - for (k in source) { - v = source[k]; - destination[k] = v; - } - } - return destination; -}; - -defaults = function(source, defaults) { - return extend({}, defaults, source); -}; - -module.exports = BaseLinter = (function() { - function BaseLinter(source1, config, rules) { - this.source = source1; - this.config = config; - this.setupRules(rules); - } - - BaseLinter.prototype.isObject = function(obj) { - return obj === Object(obj); - }; - - BaseLinter.prototype.createError = function(ruleName, attrs) { - var level; - if (attrs == null) { - attrs = {}; - } - if (attrs.level == null) { - attrs.level = this.config[ruleName].level; - } - level = attrs.level; - if (level !== 'ignore' && level !== 'warn' && level !== 'error') { - throw new Error("unknown level " + level + " for rule: " + ruleName); - } - if (level === 'error' || level === 'warn') { - attrs.rule = ruleName; - return defaults(attrs, this.config[ruleName]); - } else { - return null; - } - }; - - BaseLinter.prototype.acceptRule = function(rule) { - throw new Error('acceptRule needs to be overridden in the subclass'); - }; - - BaseLinter.prototype.setupRules = function(rules) { - var RuleConstructor, level, name, results, rule; - this.rules = []; - results = []; - for (name in rules) { - RuleConstructor = rules[name]; - level = this.config[name].level; - if (level === 'error' || level === 'warn') { - rule = new RuleConstructor(this, this.config); - if (this.acceptRule(rule)) { - results.push(this.rules.push(rule)); - } else { - results.push(void 0); - } - } else if (level !== 'ignore') { - throw new Error("unknown level " + level + " for rule: " + rule); - } else { - results.push(void 0); - } - } - return results; - }; - - BaseLinter.prototype.normalizeResult = function(p, result) { - if (result === true) { - return this.createError(p.rule.name); - } - if (this.isObject(result)) { - return this.createError(p.rule.name, result); - } - }; - - return BaseLinter; - -})(); - - - -},{}],5:[function(require,module,exports){ +},{"./../package.json":1,"./ast_linter.coffee":2,"./error_report.coffee":5,"./lexical_linter.coffee":6,"./line_linter.coffee":7,"./rules.coffee":8,"./rules/arrow_spacing.coffee":9,"./rules/braces_spacing.coffee":10,"./rules/camel_case_classes.coffee":11,"./rules/colon_assignment_spacing.coffee":12,"./rules/cyclomatic_complexity.coffee":13,"./rules/duplicate_key.coffee":14,"./rules/empty_constructor_needs_parens.coffee":15,"./rules/ensure_comprehensions.coffee":16,"./rules/eol_last.coffee":17,"./rules/indentation.coffee":18,"./rules/line_endings.coffee":19,"./rules/max_line_length.coffee":20,"./rules/missing_fat_arrows.coffee":21,"./rules/newlines_after_classes.coffee":22,"./rules/no_backticks.coffee":23,"./rules/no_debugger.coffee":24,"./rules/no_empty_functions.coffee":25,"./rules/no_empty_param_list.coffee":26,"./rules/no_implicit_braces.coffee":27,"./rules/no_implicit_parens.coffee":28,"./rules/no_interpolation_in_single_quotes.coffee":29,"./rules/no_nested_string_interpolation.coffee":30,"./rules/no_plusplus.coffee":31,"./rules/no_private_function_fat_arrows.coffee":32,"./rules/no_stand_alone_at.coffee":33,"./rules/no_tabs.coffee":34,"./rules/no_this.coffee":35,"./rules/no_throwing_strings.coffee":36,"./rules/no_trailing_semicolons.coffee":37,"./rules/no_trailing_whitespace.coffee":38,"./rules/no_unnecessary_double_quotes.coffee":39,"./rules/no_unnecessary_fat_arrows.coffee":40,"./rules/non_empty_constructor_needs_parens.coffee":41,"./rules/prefer_english_operator.coffee":42,"./rules/space_operators.coffee":43,"./rules/spacing_after_comma.coffee":44,"./rules/transform_messes_up_line_numbers.coffee":45}],5:[function(require,module,exports){ var ErrorReport; module.exports = ErrorReport = (function() { function ErrorReport(coffeelint) { this.coffeelint = coffeelint; @@ -789,11 +830,10 @@ return ErrorReport; })(); - },{}],6:[function(require,module,exports){ var BaseLinter, LexicalLinter, TokenApi, extend = 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; }, hasProp = {}.hasOwnProperty, 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; }; @@ -890,13 +930,12 @@ return LexicalLinter; })(BaseLinter); - -},{"./base_linter.coffee":4}],7:[function(require,module,exports){ -var BaseLinter, LineApi, LineLinter, configStatement, +},{"./base_linter.coffee":3}],7:[function(require,module,exports){ +var BaseLinter, LineApi, LineLinter, configShortcuts, configStatement, extend = 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; }, hasProp = {}.hasOwnProperty; LineApi = (function() { function LineApi(source, config1, tokensByLine1, literate1) { @@ -986,26 +1025,39 @@ })(); BaseLinter = require('./base_linter.coffee'); -configStatement = /coffeelint:\s*(disable|enable)(?:=([\w\s,]*))?/; +configStatement = /coffeelint:\s*((disable|enable)(-line)?)(?:=([\w\s,]*))?/; +configShortcuts = [[/\#.*noqa/, 'coffeelint: disable-line']]; + module.exports = LineLinter = (function(superClass) { extend(LineLinter, superClass); - LineLinter.configStatement = configStatement; + LineLinter.getDirective = function(line) { + var i, len, ref, replacement, shortcut; + for (i = 0, len = configShortcuts.length; i < len; i++) { + ref = configShortcuts[i], shortcut = ref[0], replacement = ref[1]; + if (line.match(shortcut)) { + return configStatement.exec(replacement); + } + } + return configStatement.exec(line); + }; 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, literate); - this.block_config = { + this.inlineConfig = { enable: {}, - disable: {} + disable: {}, + 'enable-line': {}, + 'disable-line': {} }; } LineLinter.prototype.acceptRule = function(rule) { return typeof rule.lintLine === 'function'; @@ -1044,22 +1096,22 @@ return errors; }; LineLinter.prototype.collectInlineConfig = function(line) { var cmd, i, len, r, ref, result, rules; - result = configStatement.exec(line); + result = this.constructor.getDirective(line); if (result != null) { cmd = result[1]; rules = []; - if (result[2] != null) { - ref = result[2].split(','); + if (result[4] != null) { + ref = result[4].split(','); for (i = 0, len = ref.length; i < len; i++) { r = ref[i]; rules.push(r.replace(/^\s+|\s+$/g, '')); } } - this.block_config[cmd][this.lineNumber] = rules; + this.inlineConfig[cmd][this.lineNumber] = rules; } return null; }; LineLinter.prototype.createError = function(rule, attrs) { @@ -1075,12 +1127,11 @@ return LineLinter; })(BaseLinter); - -},{"./base_linter.coffee":4}],8:[function(require,module,exports){ +},{"./base_linter.coffee":3}],8:[function(require,module,exports){ var ERROR, IGNORE, WARN; ERROR = 'error'; WARN = 'warn'; @@ -1093,11 +1144,10 @@ message: '' } }; - },{}],9:[function(require,module,exports){ var ArrowSpacing; module.exports = ArrowSpacing = (function() { function ArrowSpacing() {} @@ -1129,11 +1179,10 @@ return ArrowSpacing; })(); - },{}],10:[function(require,module,exports){ var BracesSpacing; module.exports = BracesSpacing = (function() { function BracesSpacing() {} @@ -1208,11 +1257,10 @@ return BracesSpacing; })(); - },{}],11:[function(require,module,exports){ var CamelCaseClasses, regexes; regexes = { camelCase: /^[A-Z_][a-zA-Z\d]*$/ @@ -1256,11 +1304,10 @@ return CamelCaseClasses; })(); - },{}],12:[function(require,module,exports){ var ColonAssignmentSpacing; module.exports = ColonAssignmentSpacing = (function() { function ColonAssignmentSpacing() {} @@ -1311,11 +1358,10 @@ return ColonAssignmentSpacing; })(); - },{}],13:[function(require,module,exports){ var CyclomaticComplexity; module.exports = CyclomaticComplexity = (function() { function CyclomaticComplexity() {} @@ -1371,11 +1417,10 @@ return CyclomaticComplexity; })(); - },{}],14:[function(require,module,exports){ var DuplicateKey; module.exports = DuplicateKey = (function() { DuplicateKey.prototype.rule = { @@ -1383,11 +1428,11 @@ level: 'error', message: 'Duplicate key defined in object or class', description: 'Prevents defining duplicate keys in object literals and classes' }; - DuplicateKey.prototype.tokens = ['IDENTIFIER', '{', '}']; + DuplicateKey.prototype.tokens = ['IDENTIFIER', 'PROPERTY', '{', '}']; function DuplicateKey() { this.braceScopes = []; } @@ -1396,11 +1441,11 @@ type = arg[0]; if (type === '{' || type === '}') { this.lintBrace.apply(this, arguments); return void 0; } - if (type === 'IDENTIFIER') { + if (type === 'IDENTIFIER' || type === 'PROPERTY') { return this.lintIdentifier.apply(this, arguments); } }; DuplicateKey.prototype.lintIdentifier = function(token, tokenApi) { @@ -1441,11 +1486,10 @@ return DuplicateKey; })(); - },{}],15:[function(require,module,exports){ var EmptyConstructorNeedsParens; module.exports = EmptyConstructorNeedsParens = (function() { function EmptyConstructorNeedsParens() {} @@ -1458,49 +1502,48 @@ }; EmptyConstructorNeedsParens.prototype.tokens = ['UNARY']; EmptyConstructorNeedsParens.prototype.lintToken = function(token, tokenApi) { - var expectedCallStart, expectedIdentifier, identifierIndex, peek, ref; + var identIndex, isIdent, nextToken, peek, ref, ref1, ref2; if (token[1] === 'new') { peek = tokenApi.peek.bind(tokenApi); - identifierIndex = 1; + identIndex = 1; while (true) { - expectedIdentifier = peek(identifierIndex); - expectedCallStart = peek(identifierIndex + 1); - if ((expectedIdentifier != null ? expectedIdentifier[0] : void 0) === 'IDENTIFIER') { - if ((expectedCallStart != null ? expectedCallStart[0] : void 0) === '.') { - identifierIndex += 2; + isIdent = (ref = (ref1 = peek(identIndex)) != null ? ref1[0] : void 0) === 'IDENTIFIER' || ref === 'PROPERTY'; + nextToken = peek(identIndex + 1); + if (isIdent) { + if ((nextToken != null ? nextToken[0] : void 0) === '.') { + identIndex += 2; continue; } - if ((expectedCallStart != null ? expectedCallStart[0] : void 0) === 'INDEX_START') { - while (((ref = peek(identifierIndex)) != null ? ref[0] : void 0) !== 'INDEX_END') { - identifierIndex++; + if ((nextToken != null ? nextToken[0] : void 0) === 'INDEX_START') { + while (((ref2 = peek(identIndex)) != null ? ref2[0] : void 0) !== 'INDEX_END') { + identIndex++; } continue; } } break; } - if ((expectedIdentifier != null ? expectedIdentifier[0] : void 0) === 'IDENTIFIER' && (expectedCallStart != null)) { - return this.handleExpectedCallStart(expectedCallStart); + if (isIdent && (nextToken != null)) { + return this.handleExpectedCallStart(nextToken); } } }; - EmptyConstructorNeedsParens.prototype.handleExpectedCallStart = function(expectedCallStart) { - if (expectedCallStart[0] !== 'CALL_START') { + EmptyConstructorNeedsParens.prototype.handleExpectedCallStart = function(isCallStart) { + if (isCallStart[0] !== 'CALL_START') { return true; } }; return EmptyConstructorNeedsParens; })(); - },{}],16:[function(require,module,exports){ var EnsureComprehensions, 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 = EnsureComprehensions = (function() { @@ -1595,11 +1638,10 @@ return EnsureComprehensions; })(); - },{}],17:[function(require,module,exports){ var EOLLast; module.exports = EOLLast = (function() { function EOLLast() {} @@ -1626,11 +1668,10 @@ return EOLLast; })(); - },{}],18:[function(require,module,exports){ var Indentation, 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 = Indentation = (function() { @@ -1812,11 +1853,10 @@ return Indentation; })(); - },{}],19:[function(require,module,exports){ var LineEndings; module.exports = LineEndings = (function() { function LineEndings() {} @@ -1857,11 +1897,10 @@ return LineEndings; })(); - },{}],20:[function(require,module,exports){ var MaxLineLength, regexes; regexes = { literateComment: /^\#\s/, @@ -1903,11 +1942,10 @@ return MaxLineLength; })(); - },{}],21:[function(require,module,exports){ var MissingFatArrows, any, containsButIsnt, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 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; }; @@ -2055,11 +2093,10 @@ return MissingFatArrows; })(); - },{}],22:[function(require,module,exports){ var NewlinesAfterClasses; module.exports = NewlinesAfterClasses = (function() { function NewlinesAfterClasses() {} @@ -2097,11 +2134,11 @@ befores = 1; afters = 1; comment = 0; outdent = token.origin[2].first_line; start = Math.min(lineNumber, outdent); - trueLine = Infinity; + trueLine = 2e308; while (/^\s*(#|$)/.test(lines[start + afters])) { if (/^\s*#/.test(lines[start + afters])) { comment += 1; } else { trueLine = Math.min(trueLine, start + afters); @@ -2131,11 +2168,10 @@ return NewlinesAfterClasses; })(); - },{}],23:[function(require,module,exports){ var NoBackticks; module.exports = NoBackticks = (function() { function NoBackticks() {} @@ -2156,11 +2192,10 @@ return NoBackticks; })(); - },{}],24:[function(require,module,exports){ var NoDebugger; module.exports = NoDebugger = (function() { function NoDebugger() {} @@ -2171,21 +2206,21 @@ message: 'Found debugging code', console: false, description: 'This rule detects `debugger` and optionally `console` calls\nThis rule is `warn` by default.' }; - NoDebugger.prototype.tokens = ['DEBUGGER', 'IDENTIFIER']; + NoDebugger.prototype.tokens = ['STATEMENT', 'DEBUGGER', 'IDENTIFIER']; NoDebugger.prototype.lintToken = function(token, tokenApi) { - var method, ref, ref1; - if (token[0] === 'DEBUGGER') { + var method, ref, ref1, ref2; + if (((ref = token[0]) === 'DEBUGGER' || ref === 'STATEMENT') && token[1] === 'debugger') { return { context: "found '" + token[0] + "'" }; } - if ((ref = tokenApi.config[this.rule.name]) != null ? ref.console : void 0) { - if (token[1] === 'console' && ((ref1 = tokenApi.peek(1)) != null ? ref1[0] : void 0) === '.') { + if ((ref1 = tokenApi.config[this.rule.name]) != null ? ref1.console : void 0) { + if (token[1] === 'console' && ((ref2 = tokenApi.peek(1)) != null ? ref2[0] : void 0) === '.') { method = tokenApi.peek(2); return { context: "found 'console." + method[1] + "'" }; } @@ -2195,11 +2230,10 @@ return NoDebugger; })(); - },{}],25:[function(require,module,exports){ var NoEmptyFunctions, isEmptyCode; isEmptyCode = function(node, astApi) { var nodeName; @@ -2240,11 +2274,10 @@ return NoEmptyFunctions; })(); - },{}],26:[function(require,module,exports){ var NoEmptyParamList; module.exports = NoEmptyParamList = (function() { function NoEmptyParamList() {} @@ -2267,11 +2300,10 @@ return NoEmptyParamList; })(); - },{}],27:[function(require,module,exports){ var NoImplicitBraces; module.exports = NoImplicitBraces = (function() { NoImplicitBraces.prototype.rule = { @@ -2280,26 +2312,34 @@ message: 'Implicit braces are forbidden', strict: true, description: 'This rule prohibits implicit braces when declaring object literals.\nImplicit braces can make code more difficult to understand,\nespecially when used in combination with optional parenthesis.\n<pre>\n<code># Do you find this code ambiguous? Is it a\n# function call with three arguments or four?\nmyFunction a, b, 1:2, 3:4\n\n# While the same code written in a more\n# explicit manner has no ambiguity.\nmyFunction(a, b, {1:2, 3:4})\n</code>\n</pre>\nImplicit braces are permitted by default, since their use is\nidiomatic CoffeeScript.' }; - NoImplicitBraces.prototype.tokens = ['{', 'OUTDENT', 'CLASS', 'IDENTIFIER']; + NoImplicitBraces.prototype.tokens = ['{', 'OUTDENT', 'CLASS', 'IDENTIFIER', 'EXTENDS']; function NoImplicitBraces() { this.isClass = false; - this.className = void 0; + this.className = ''; } NoImplicitBraces.prototype.lintToken = function(token, tokenApi) { - var lineNum, peekTwo, prevToken, type, val; + var _type, _val, c, lineNum, peekIdent, prevToken, ref, ref1, type, val; type = token[0], val = token[1], lineNum = token[2]; if (type === 'OUTDENT' || type === 'CLASS') { return this.trackClass.apply(this, arguments); } - if (type === 'IDENTIFIER' && this.isClass && ((this.className == null) || tokenApi.peek(-1)[0] === 'EXTENDS')) { - this.className = val; + if (type === 'EXTENDS') { + this.className = ''; + return; } + if (type === 'IDENTIFIER' && this.isClass && this.className === '') { + c = 0; + while ((ref = tokenApi.peek(c)[0]) === 'IDENTIFIER' || ref === 'PROPERTY' || ref === '.') { + this.className += tokenApi.peek(c)[1]; + c++; + } + } if (token.generated && type === '{') { if (!tokenApi.config[this.rule.name].strict) { prevToken = tokenApi.peek(-1)[0]; if (prevToken === 'INDENT' || prevToken === 'TERMINATOR') { return; @@ -2308,12 +2348,20 @@ if (this.isClass) { prevToken = tokenApi.peek(-1)[0]; if (prevToken === 'TERMINATOR') { return; } - peekTwo = tokenApi.peek(-2); - if (peekTwo[0] === 'IDENTIFIER' && peekTwo[1] === this.className) { + peekIdent = ''; + c = -2; + while ((ref1 = tokenApi.peek(c), _type = ref1[0], _val = ref1[1], ref1)) { + if (_type !== 'IDENTIFIER' && _type !== 'PROPERTY' && _type !== '.') { + break; + } + peekIdent = _val + peekIdent; + c--; + } + if (peekIdent === this.className) { return; } } return true; } @@ -2325,21 +2373,20 @@ if (n0 === 'OUTDENT' && n1 === 'TERMINATOR') { this.isClass = false; } if (n0 === 'CLASS') { this.isClass = true; - this.className = void 0; + this.className = ''; } return null; }; return NoImplicitBraces; })(); - },{}],28:[function(require,module,exports){ var NoImplicitParens; module.exports = NoImplicitParens = (function() { function NoImplicitParens() {} @@ -2378,11 +2425,10 @@ return NoImplicitParens; })(); - },{}],29:[function(require,module,exports){ var NoInterpolationInSingleQuotes; module.exports = NoInterpolationInSingleQuotes = (function() { function NoInterpolationInSingleQuotes() {} @@ -2406,11 +2452,10 @@ return NoInterpolationInSingleQuotes; })(); - },{}],30:[function(require,module,exports){ var NoNestedStringInterpolation; module.exports = NoNestedStringInterpolation = (function() { NoNestedStringInterpolation.prototype.rule = { @@ -2456,11 +2501,10 @@ return NoNestedStringInterpolation; })(); - },{}],31:[function(require,module,exports){ var NoPlusPlus; module.exports = NoPlusPlus = (function() { function NoPlusPlus() {} @@ -2483,11 +2527,10 @@ return NoPlusPlus; })(); - },{}],32:[function(require,module,exports){ var NoPrivateFunctionFatArrows, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 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; }; @@ -2581,11 +2624,10 @@ return NoPrivateFunctionFatArrows; })(); - },{}],33:[function(require,module,exports){ var NoStandAloneAt; module.exports = NoStandAloneAt = (function() { function NoStandAloneAt() {} @@ -2598,31 +2640,27 @@ }; NoStandAloneAt.prototype.tokens = ['@']; NoStandAloneAt.prototype.lintToken = function(token, tokenApi) { - var isDot, isIdentifier, isIndexStart, isValidProtoProperty, nextToken, protoProperty, spaced; - nextToken = tokenApi.peek(); - spaced = token.spaced; - isIdentifier = nextToken[0] === 'IDENTIFIER'; - isIndexStart = nextToken[0] === 'INDEX_START'; - isDot = nextToken[0] === '.'; - if (nextToken[0] === '::') { - protoProperty = tokenApi.peek(2); - isValidProtoProperty = protoProperty[0] === 'IDENTIFIER'; - } - if (spaced || (!isIdentifier && !isIndexStart && !isDot && !isValidProtoProperty)) { + var isAStart, isDot, isProp, isProtoProp, nextToken, noSpace, ref, ref1; + nextToken = tokenApi.peek()[0]; + noSpace = !token.spaced; + isProp = nextToken === 'IDENTIFIER' || nextToken === 'PROPERTY'; + isAStart = nextToken === 'INDEX_START' || nextToken === 'CALL_START'; + isDot = nextToken === '.'; + isProtoProp = nextToken === '::' && ((ref = (ref1 = tokenApi.peek(2)) != null ? ref1[0] : void 0) === 'IDENTIFIER' || ref === 'PROPERTY'); + if (!(isDot || (noSpace && (isProp || isAStart || isProtoProp)))) { return true; } }; return NoStandAloneAt; })(); - },{}],34:[function(require,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/; @@ -2650,11 +2688,10 @@ return NoTabs; })(); - },{}],35:[function(require,module,exports){ var NoThis; module.exports = NoThis = (function() { function NoThis() {} @@ -2680,11 +2717,10 @@ return NoThis; })(); - },{}],36:[function(require,module,exports){ var NoThrowingStrings; module.exports = NoThrowingStrings = (function() { function NoThrowingStrings() {} @@ -2708,11 +2744,10 @@ return NoThrowingStrings; })(); - },{}],37:[function(require,module,exports){ var NoTrailingSemicolons, regexes, 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; }, slice = [].slice; @@ -2761,11 +2796,10 @@ return NoTrailingSemicolons; })(); - },{}],38:[function(require,module,exports){ var NoTrailingWhitespace, regexes; regexes = { trailingWhitespace: /[^\s]+[\t ]+\r?$/, @@ -2825,11 +2859,10 @@ return NoTrailingWhitespace; })(); - },{}],39:[function(require,module,exports){ var NoUnnecessaryDoubleQuotes; module.exports = NoUnnecessaryDoubleQuotes = (function() { NoUnnecessaryDoubleQuotes.prototype.rule = { @@ -2883,11 +2916,10 @@ return NoUnnecessaryDoubleQuotes; })(); - },{}],40:[function(require,module,exports){ var NoUnnecessaryFatArrows, any, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; any = function(arr, test) { @@ -2941,22 +2973,24 @@ NoUnnecessaryFatArrows.prototype.isValue = function(node) { return this.astApi.getNodeName(node) === 'Value'; }; NoUnnecessaryFatArrows.prototype.isThis = function(node) { - return this.isValue(node) && node.base.value === 'this'; + var ref; + return ((ref = node.constructor) != null ? ref.name : void 0) === 'ThisLiteral' || this.isValue(node) && node.base.value === 'this'; }; NoUnnecessaryFatArrows.prototype.needsFatArrow = function(node) { return this.isCode(node) && (any(node.params, (function(_this) { return function(param) { return param.contains(_this.isThis) != null; }; })(this)) || (node.body.contains(this.isThis) != null) || (node.body.contains((function(_this) { return function(child) { + var ref; if (!_this.astApi.getNodeName(child)) { - return (child.isSuper != null) && child.isSuper; + return ((ref = child.constructor) != null ? ref.name : void 0) === 'SuperCall' || ((child.isSuper != null) && child.isSuper); } else { return _this.isFatArrowCode(child) && _this.needsFatArrow(child); } }; })(this)) != null)); @@ -2965,11 +2999,10 @@ return NoUnnecessaryFatArrows; })(); - },{}],41:[function(require,module,exports){ var NonEmptyConstructorNeedsParens, ParentClass, extend = 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; }, hasProp = {}.hasOwnProperty; @@ -2987,22 +3020,21 @@ level: 'ignore', message: 'Invoking a constructor without parens and with arguments', description: 'Requires constructors with parameters to include the parens' }; - NonEmptyConstructorNeedsParens.prototype.handleExpectedCallStart = function(expectedCallStart) { - if (expectedCallStart[0] === 'CALL_START' && expectedCallStart.generated) { + NonEmptyConstructorNeedsParens.prototype.handleExpectedCallStart = function(isCallStart) { + if (isCallStart[0] === 'CALL_START' && isCallStart.generated) { return true; } }; return NonEmptyConstructorNeedsParens; })(ParentClass); - },{"./empty_constructor_needs_parens.coffee":15}],42:[function(require,module,exports){ var PreferEnglishOperator; module.exports = PreferEnglishOperator = (function() { function PreferEnglishOperator() {} @@ -3060,11 +3092,10 @@ return PreferEnglishOperator; })(); - },{}],43:[function(require,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() { @@ -3169,11 +3200,10 @@ return SpaceOperators; })(); - },{}],44:[function(require,module,exports){ var SpacingAfterComma; module.exports = SpacingAfterComma = (function() { SpacingAfterComma.prototype.rule = { @@ -3217,11 +3247,10 @@ return SpacingAfterComma; })(); - },{}],45:[function(require,module,exports){ var TransformMessesUpLineNumbers; module.exports = TransformMessesUpLineNumbers = (function() { function TransformMessesUpLineNumbers() {} @@ -3240,8 +3269,7 @@ return TransformMessesUpLineNumbers; })(); - -},{}]},{},[1])(1) +},{}]},{},[4])(4) }); \ No newline at end of file