diff --git a/.eslintrc b/.eslintrc index ea5635e..1366696 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,6 +17,7 @@ rules: eqeqeq: 2 guard-for-in: 2 handle-callback-err: 2 + key-spacing: 0 max-depth: [ 1, 6 ] max-nested-callbacks: [ 1, 4 ] # string can exceed 80 chars, but should not overflow github website :) @@ -30,13 +31,14 @@ rules: no-eq-null: 2 no-floating-decimal: 2 no-lonely-if: 2 + no-multi-spaces: 0 no-process-exit: 0 no-trailing-spaces: 2 no-underscore-dangle: 0 quotes: [ 2, single, avoid-escape ] radix: 2 space-after-keywords: [ 2, always ] # Fixed in master - space-in-brackets: [ 1, always ] + space-in-brackets: [ 1, always, { propertyName: false } ] # temporary no-func-assign: 0 diff --git a/lib/linkifier.js b/lib/linkifier.js index 19ad529..3880e13 100644 --- a/lib/linkifier.js +++ b/lib/linkifier.js @@ -7,7 +7,7 @@ var assign = require('./common/utils').assign; var Ruler = require('./ruler'); -var rules = [ +var _rules = [ require('./rules_text/linkify') ]; @@ -19,8 +19,8 @@ function Linkifier() { this.ruler = new Ruler(this.rulesUpdate.bind(this)); - for (var i = 0; i < rules.length; i++) { - this.ruler.after(rules[i]); + for (var i = 0; i < _rules.length; i++) { + this.ruler.after(_rules[i]); } } diff --git a/lib/parser_block.js b/lib/parser_block.js index d750557..1610d54 100644 --- a/lib/parser_block.js +++ b/lib/parser_block.js @@ -8,19 +8,19 @@ var Ruler = require('./ruler'); var State = require('./rules_block/state_block'); -var rules = []; +var _rules = []; // `list` should be after `hr`, but before `heading` -rules.push([ require('./rules_block/code') ]); -rules.push([ require('./rules_block/fences'), 'paragraph', 'blockquote', 'list' ]); -rules.push([ require('./rules_block/blockquote'), 'paragraph', 'blockquote', 'list' ]); -rules.push([ require('./rules_block/hr'), 'paragraph', 'blockquote', 'list' ]); -rules.push([ require('./rules_block/list'), 'paragraph', 'blockquote' ]); -rules.push([ require('./rules_block/heading'), 'paragraph', 'blockquote' ]); -rules.push([ require('./rules_block/lheading') ]); -rules.push([ require('./rules_block/htmlblock'), 'paragraph', 'blockquote' ]); -rules.push([ require('./rules_block/table'), 'paragraph' ]); -rules.push([ require('./rules_block/paragraph') ]); +_rules.push([ require('./rules_block/code') ]); +_rules.push([ require('./rules_block/fences'), 'paragraph', 'blockquote', 'list' ]); +_rules.push([ require('./rules_block/blockquote'), 'paragraph', 'blockquote', 'list' ]); +_rules.push([ require('./rules_block/hr'), 'paragraph', 'blockquote', 'list' ]); +_rules.push([ require('./rules_block/list'), 'paragraph', 'blockquote' ]); +_rules.push([ require('./rules_block/heading'), 'paragraph', 'blockquote' ]); +_rules.push([ require('./rules_block/lheading') ]); +_rules.push([ require('./rules_block/htmlblock'), 'paragraph', 'blockquote' ]); +_rules.push([ require('./rules_block/table'), 'paragraph' ]); +_rules.push([ require('./rules_block/paragraph') ]); // Block Parser class @@ -33,8 +33,8 @@ function ParserBlock() { this.ruler = new Ruler(this.rulesUpdate.bind(this)); - for (var i = 0; i < rules.length; i++) { - this.ruler.after(rules[i][0], rules[i].slice(1)); + for (var i = 0; i < _rules.length; i++) { + this.ruler.after(_rules[i][0], _rules[i].slice(1)); } } diff --git a/lib/parser_inline.js b/lib/parser_inline.js index 520645f..728a7fc 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -9,22 +9,21 @@ var StateInline = require('./rules_inline/state_inline'); //////////////////////////////////////////////////////////////////////////////// // Parser rules -var rules = []; - - -// Pure text -rules.push(require('./rules_inline/text')); -rules.push(require('./rules_inline/newline')); -rules.push(require('./rules_inline/escape')); -rules.push(require('./rules_inline/backticks')); -rules.push(require('./rules_inline/del')); -rules.push(require('./rules_inline/ins')); -rules.push(require('./rules_inline/mark')); -rules.push(require('./rules_inline/emphasis')); -rules.push(require('./rules_inline/links')); -rules.push(require('./rules_inline/autolink')); -rules.push(require('./rules_inline/htmltag')); -rules.push(require('./rules_inline/entity')); +var _rules = []; + +_rules.push(require('./rules_inline/text')); +_rules.push(require('./rules_inline/newline')); +_rules.push(require('./rules_inline/escape')); +_rules.push(require('./rules_inline/backticks')); +_rules.push(require('./rules_inline/del')); +_rules.push(require('./rules_inline/ins')); +_rules.push(require('./rules_inline/mark')); +_rules.push(require('./rules_inline/emphasis')); +_rules.push(require('./rules_inline/links')); +_rules.push(require('./rules_inline/autolink')); +_rules.push(require('./rules_inline/htmltag')); +_rules.push(require('./rules_inline/entity')); + var BAD_PROTOCOLS = [ 'vbscript', 'javascript', 'file' ]; @@ -58,8 +57,8 @@ function ParserInline() { this.ruler = new Ruler(this.rulesUpdate.bind(this)); - for (var i = 0; i < rules.length; i++) { - this.ruler.after(rules[i]); + for (var i = 0; i < _rules.length; i++) { + this.ruler.after(_rules[i]); } } @@ -74,7 +73,6 @@ ParserInline.prototype.rulesUpdate = function () { // ParserInline.prototype.skipToken = function (state) { var i, cached_pos, pos = state.pos, - rules = this._rules, len = this._rules.length; if ((cached_pos = state.cacheGet(pos)) > 0) { @@ -83,7 +81,7 @@ ParserInline.prototype.skipToken = function (state) { } for (i = 0; i < len; i++) { - if (rules[i](state, true)) { + if (this._rules[i](state, true)) { state.cacheSet(pos, state.pos); return; } @@ -98,7 +96,6 @@ ParserInline.prototype.skipToken = function (state) { // ParserInline.prototype.tokenize = function (state) { var ok, i, - rules = this._rules, len = this._rules.length, end = state.posMax; @@ -112,7 +109,7 @@ ParserInline.prototype.tokenize = function (state) { // - return true for (i = 0; i < len; i++) { - ok = rules[i](state, false); + ok = this._rules[i](state, false); if (ok) { break; } } diff --git a/lib/renderer.js b/lib/renderer.js index 43342ae..078b45c 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -282,13 +282,13 @@ Renderer.prototype.renderInline = function (tokens, options) { Renderer.prototype.render = function (tokens, options) { var i, len, result = '', - rules = this.rules; + _rules = this.rules; for (i = 0, len = tokens.length; i < len; i++) { if (tokens[i].type === 'inline') { result += this.renderInline(tokens[i].children, options); } else { - result += rules[tokens[i].type](tokens, i, options); + result += _rules[tokens[i].type](tokens, i, options); } } diff --git a/lib/rules_inline/autolink.js b/lib/rules_inline/autolink.js index caa6ecd..4669d59 100644 --- a/lib/rules_inline/autolink.js +++ b/lib/rules_inline/autolink.js @@ -1,5 +1,6 @@ // Process autolinks '' +'use strict'; var url_schemas = require('../common/url_schemas'); diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.js index f80c1ce..394bfa6 100644 --- a/lib/rules_inline/backticks.js +++ b/lib/rules_inline/backticks.js @@ -1,5 +1,7 @@ // Parse backticks +'use strict'; + module.exports = function backticks(state, silent) { var start, max, marker, matchStart, matchEnd, pos = state.pos, diff --git a/lib/rules_inline/escape.js b/lib/rules_inline/escape.js index 40e9249..09dee0b 100644 --- a/lib/rules_inline/escape.js +++ b/lib/rules_inline/escape.js @@ -1,5 +1,7 @@ // Proceess escaped chars and hardbreaks +'use strict'; + var ESCAPED = []; for (var i = 0; i < 256; i++) { ESCAPED.push(0); } diff --git a/lib/rules_inline/newline.js b/lib/rules_inline/newline.js index d3188bb..926049b 100644 --- a/lib/rules_inline/newline.js +++ b/lib/rules_inline/newline.js @@ -1,5 +1,7 @@ // Proceess '\n' +'use strict'; + module.exports = function newline(state, silent) { var pmax, max, pos = state.pos; diff --git a/lib/rules_inline/text.js b/lib/rules_inline/text.js index 8a60a64..93fe005 100644 --- a/lib/rules_inline/text.js +++ b/lib/rules_inline/text.js @@ -1,6 +1,8 @@ // Skip text characters for text token, place those to pendibg buffer // and increment current pos +'use strict'; + module.exports = function text(state, silent) { var str = state.src.slice(state.pos), next = str.search(state.parser.textMatch); diff --git a/lib/typographer.js b/lib/typographer.js index 825279f..2166ae0 100644 --- a/lib/typographer.js +++ b/lib/typographer.js @@ -11,7 +11,7 @@ var assign = require('./common/utils').assign; var Ruler = require('./ruler'); -var rules = [ +var _rules = [ require('./rules_text/replace'), require('./rules_text/smartquotes') ]; @@ -24,8 +24,8 @@ function Typographer() { this.ruler = new Ruler(this.rulesUpdate.bind(this)); - for (var i = 0; i < rules.length; i++) { - this.ruler.after(rules[i]); + for (var i = 0; i < _rules.length; i++) { + this.ruler.after(_rules[i]); } } diff --git a/package.json b/package.json index 6c69543..40481b4 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "autoprefixer-stylus": "^0.3.0", "benchmark": "^1.0.0", "browserify": "*", - "eslint": "0.8.0", + "eslint": "0.9.1", "eslint-plugin-nodeca": "^1.0.0", "istanbul": "*", "jade": "^1.6.0",