diff --git a/.jshintignore b/.eslintignore similarity index 89% rename from .jshintignore rename to .eslintignore index bd6f1d4..d85148f 100644 --- a/.jshintignore +++ b/.eslintignore @@ -1,5 +1,4 @@ -.git/ benchmark/implementations/ -node_modules/ demo/ dist/ +node_modules/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..9e28e7a --- /dev/null +++ b/.eslintrc @@ -0,0 +1,47 @@ +env: + node: true + browser: false + +plugins: + - nodeca + +rules: + block-scoped-var: 2 + brace-style: [ 2, '1tbs', { allowSingleLine: true } ] + camelcase: 0 + consistent-return: 2 + consistent-this: [ 2, self ] + curly: [ 2, all ] + default-case: 2 + eol-last: 2 + eqeqeq: 2 + guard-for-in: 2 + handle-callback-err: 2 + max-depth: [ 1, 3 ] + max-nested-callbacks: [ 1, 4 ] + # string can exceed 80 chars, but should not overflow github website :) + max-len: [ 2, 120, 1000 ] + no-alert: 2 + no-bitwise: 2 + no-comma-dangle: 2 + no-console: 2 + no-div-regex: 2 + no-else-return: 2 + no-eq-null: 2 + no-floating-decimal: 2 + no-lonely-if: 2 + 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 ] + + # temporary + no-func-assign: 0 + + # + # Our custom rules + # + nodeca/indent: [ 2, spaces, 2 ] diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 6364b4a..0000000 --- a/.jshintrc +++ /dev/null @@ -1,82 +0,0 @@ -{ - // Enforcing Options ///////////////////////////////////////////////////////// - - "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). - // false - specific for js-yaml - - "camelcase" : false, // Require variable names to be camelCase style or UPPER_CASE - "curly" : true, // Require {} for every new block or scope. - "eqeqeq" : true, // Require triple equals i.e. `===`. - "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. - "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` - "indent" : 2, // This option enforces specific tab width for your code - "latedef" : false, // Prohibit hariable use before definition. - "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. - "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. - "noempty" : true, // Prohibit use of empty blocks. - "nonew" : true, // Prohibit use of constructors for side-effects. - "plusplus" : false, // Prohibit use of `++` & `--`. - "quotmark" : false, // Enforces the consistency of quotation marks used throughout your code. - "regexp" : false, // Prohibit `.` and `[^...]` in regular expressions. - "undef" : true, // Require all non-global variables be declared before they are used. - "unused" : false, // This option warns when you define and never use your variables. - "strict" : true, // Require `use strict` pragma in every file. - "trailing" : true, // Prohibit trailing whitespaces. - "maxparams" : 6, // Enforce max number of formal parameters allowed per function - "maxdepth" : 5, // Enforce max depth of nested blocks - "maxstatements" : false, // Enforce max amount of statements per function - "maxcomplexity" : false, // Enforce cyclomatic complexity level - - // Relaxing Options ////////////////////////////////////////////////////////// - - "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). - "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. - "debug" : false, // Allow debugger statements e.g. browser breakpoints. - "eqnull" : false, // Tolerate use of `== null`. -//"es5" : true, // Allow ECMAScript 5 syntax. - "esnext" : false, // Allow ES.next specific features such as const and let - "evil" : false, // Tolerate use of `eval`. - "expr" : false, // Tolerate `ExpressionStatement` as Programs. - "funcscope" : false, // Tolerate declaring variables inside of control structures while accessing them later - "globalstrict" : true, // Allow global "use strict" (also enables 'strict'). - "iterator" : false, // Allow usage of __iterator__ property. - "lastsemic" : false, // Tolerate semicolon omited for the last statement. - "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. - "laxcomma" : true, // This option suppresses warnings about comma-first coding style - "loopfunc" : false, // Allow functions to be defined within loops. - "multistr" : false, // Tolerate multi-line strings. - "onecase" : false, // Tolerate swithes with only one case. - "proto" : false, // Allow usage of __proto__ property. - "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. - "scripturl" : true, // Tolerate script-targeted URLs. - "smarttabs" : false, // Allow mixed tabs and spaces when the latter are used for alignmnent only. - "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. - "sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. - "supernew" : true, // Tolerate `new function () { ... };` and `new Object;`. - - // Environments ////////////////////////////////////////////////////////////// - - "browser" : false, // Defines globals exposed by modern browsers - "couch" : false, // Defines globals exposed by CouchDB - "devel" : false, // Allow developments statements e.g. `console.log();`. - "dojo" : false, // Defines globals exposed by the Dojo Toolkit - "jquery" : false, // Defines globals exposed by the jQuery - "mootools" : false, // Defines globals exposed by the MooTools - "node" : true, // Defines globals exposed when running under Node.JS - "nonstandard" : false, // Defines non-standard but widely adopted globals such as escape and unescape - "prototypejs" : false, // Defines globals exposed by the Prototype - "rhino" : false, // Defines globals exposed when running under Rhino - "worker" : false, // Defines globals exposed when running Web Worker - "wsh" : false, // Defines globals exposed when running under WSH - - // Legacy //////////////////////////////////////////////////////////////////// - - "nomen" : false, // Prohibit use of initial or trailing underbars in names. - "onevar" : false, // Allow only one `var` statement per function. - "passfail" : false, // Stop on first error. - "white" : false, // Check against strict whitespace and indentation rules. - - // Other ///////////////////////////////////////////////////////////////////// - - "maxerr" : 100 // Maximum error before stopping. -} diff --git a/Makefile b/Makefile index 7c94ba7..99a25db 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ demo: lint browserify lint: - jshint . --show-non-errors + eslint ./ test: lint diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 3629308..6fe04ae 100755 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +/*eslint no-console:0*/ 'use strict'; @@ -15,8 +16,8 @@ var IMPLS = []; fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) { - var file = path.join(IMPLS_DIRECTORY, name), - code = require(file); + var file = path.join(IMPLS_DIRECTORY, name); + var code = require(file); IMPLS_PATHS[name] = file; IMPLS.push({ @@ -67,9 +68,7 @@ fs.readdirSync(SAMPLES_DIRECTORY).sort().forEach(function (sample) { onComplete: onComplete, - defer: !!impl.code.async, - - fn: function (deferred) { + fn: function () { impl.code.run(content.string); return; } diff --git a/benchmark/profile.js b/benchmark/profile.js index 8c6578f..08e41e5 100644 --- a/benchmark/profile.js +++ b/benchmark/profile.js @@ -1,12 +1,13 @@ 'use strict'; var fs = require('fs'); +var path = require('path'); var Remarkable = require('../'); var md = new Remarkable(); -var data = fs.readFileSync(__dirname +'/samples/lorem1.txt', 'utf8'); +var data = fs.readFileSync(path.join(__dirname, '/samples/lorem1.txt', 'utf8')); -for (var i=0; i<20000; i++) { +for (var i = 0; i < 20000; i++) { md.render(data); } diff --git a/bin/remarkable.js b/bin/remarkable.js index 5ce1148..b1899f2 100755 --- a/bin/remarkable.js +++ b/bin/remarkable.js @@ -1,5 +1,5 @@ #!/usr/bin/env node - +/*eslint no-console:0*/ 'use strict'; @@ -17,13 +17,13 @@ var cli = new argparse.ArgumentParser({ addHelp: true }); -cli.addArgument(['file'], { +cli.addArgument([ 'file' ], { help: 'File to read', nargs: '?', defaultValue: '-' }); -cli.addArgument(['-t', '--trace'], { +cli.addArgument([ '-t', '--trace' ], { help: 'Show stack trace on error', action: 'storeTrue' }); @@ -56,7 +56,7 @@ readFile(options.file, 'utf8', function (error, input) { var output, md; if (error) { - if ('ENOENT' === error.code) { + if (error.code === 'ENOENT') { console.error('File not found: ' + options.file); process.exit(2); } diff --git a/lib/helpers.js b/lib/helpers.js index fd8d6bf..087ca64 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -64,4 +64,4 @@ exports.isEmpty = isEmpty; exports.skipEmptyLines = skipEmptyLines; exports.skipSpaces = skipSpaces; exports.skipChars = skipChars; -exports.getLines = getLines; \ No newline at end of file +exports.getLines = getLines; diff --git a/lib/lexer_block/blockquote.js b/lib/lexer_block/blockquote.js index 73f0471..c619599 100644 --- a/lib/lexer_block/blockquote.js +++ b/lib/lexer_block/blockquote.js @@ -9,7 +9,7 @@ var getLines = require('../helpers').getLines; module.exports = function blockquote(state, startLine, endLine, silent) { - var marker, nextLine, oldBMarks, lastLineEmpty, subState, + var nextLine, lastLineEmpty, subState, rules_named = state.lexerBlock.rules_named, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; diff --git a/lib/lexer_block/code.js b/lib/lexer_block/code.js index 5c11980..4480075 100644 --- a/lib/lexer_block/code.js +++ b/lib/lexer_block/code.js @@ -39,4 +39,4 @@ module.exports = function code(state, startLine, endLine, silent) { state.line = nextLine; return true; -}; \ No newline at end of file +}; diff --git a/lib/lexer_block/fences.js b/lib/lexer_block/fences.js index 93fb719..4c61696 100644 --- a/lib/lexer_block/fences.js +++ b/lib/lexer_block/fences.js @@ -9,7 +9,7 @@ var skipChars = require('../helpers').skipChars; var getLines = require('../helpers').getLines; -module.exports =function fences(state, startLine, endLine, silent) { +module.exports = function fences(state, startLine, endLine, silent) { var marker, len, params, nextLine, mem, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; @@ -35,7 +35,7 @@ module.exports =function fences(state, startLine, endLine, silent) { // search end of block nextLine = startLine; - do { + for (;;) { nextLine++; if (nextLine >= endLine) { @@ -63,8 +63,7 @@ module.exports =function fences(state, startLine, endLine, silent) { // found! break; - - } while (true); + } if (silent) { return true; } @@ -76,4 +75,4 @@ module.exports =function fences(state, startLine, endLine, silent) { state.line = skipEmptyLines(state, nextLine + 1); return true; -}; \ No newline at end of file +}; diff --git a/lib/lexer_block/heading.js b/lib/lexer_block/heading.js index 8bd8078..3d0929a 100644 --- a/lib/lexer_block/heading.js +++ b/lib/lexer_block/heading.js @@ -69,4 +69,4 @@ module.exports = function heading(state, startLine, endLine, silent) { state.line = skipEmptyLines(state, ++startLine); return true; -}; \ No newline at end of file +}; diff --git a/lib/lexer_block/lheading.js b/lib/lexer_block/lheading.js index 10ab968..5bf5e04 100644 --- a/lib/lexer_block/lheading.js +++ b/lib/lexer_block/lheading.js @@ -33,6 +33,8 @@ module.exports = function lheading(state, startLine, endLine, silent) { if (pos < max) { return false; } + if (silent) { return true; } + state.tokens.push({ type: 'heading_open', level: marker === 0x3D/* = */ ? 1 : 2 }); state.lexerInline.tokenize(state, state.bMarks[startLine], state.eMarks[startLine]); state.tokens.push({ type: 'heading_close', level: marker === 0x3D/* = */ ? 1 : 2 }); diff --git a/lib/lexer_block/list.js b/lib/lexer_block/list.js index 609c04f..86ec476 100644 --- a/lib/lexer_block/list.js +++ b/lib/lexer_block/list.js @@ -8,14 +8,13 @@ var skipEmptyLines = require('../helpers').skipEmptyLines; function bullet_item(state, startLine, endLine, silent) { - var marker, nextLine, start, + var marker, nextLine, rules_named = state.lexerBlock.rules_named, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; // TODO: supporting list with only one paragraph for now - start = pos; if (pos > max) { return false; } marker = state.src.charCodeAt(pos++); @@ -79,4 +78,3 @@ module.exports = function list(state, startLine, endLine, silent) { } return false; }; - diff --git a/lib/renderer.js b/lib/renderer.js index 5431769..bc803b1 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -18,18 +18,18 @@ function unescapeMd(str) { var rules = {}; -rules.blockquote_open = function (state, token) { +rules.blockquote_open = function (state /*, token*/) { state.result += '
'; }; -rules.blockquote_close = function (state, token) { +rules.blockquote_close = function (state /*, token*/) { state.result += '
\n'; }; -rules.bullet_list_open = function (state, token) { +rules.bullet_list_open = function (state /*, token*/) { state.result += '\n'; }; @@ -59,23 +59,23 @@ rules.heading_close = function (state, token) { }; -rules.hr = function (state, token) { +rules.hr = function (state/*, token*/) { state.result += '
\n'; }; -rules.list_item_open = function (state, token) { +rules.list_item_open = function (state /*, token*/) { state.result += '
  • '; }; -rules.list_item_close = function (state, token) { +rules.list_item_close = function (state /*, token*/) { state.result += '
  • \n'; }; -rules.paragraph_open = function (state, token) { +rules.paragraph_open = function (state /*, token*/) { state.result += '

    '; }; -rules.paragraph_close = function (state, token) { +rules.paragraph_close = function (state /*, token*/) { state.result += '

    \n'; }; @@ -98,7 +98,7 @@ Renderer.prototype.render = function (state) { // TODO: temporary check if (!rule) { - throw Error('Renderer error: unknown token ' + tokens[i].type); + throw new Error('Renderer error: unknown token ' + tokens[i].type); } rule(state, tokens[i]); diff --git a/lib/state.js b/lib/state.js index 5669502..3c8db0d 100644 --- a/lib/state.js +++ b/lib/state.js @@ -44,7 +44,7 @@ function State(src, lexerBlock, lexerInline, renderer, tokens, options) { indent = 0; indent_found = false; - for(start = pos = indent = 0, len = s.length; pos < len; pos++) { + for (start = pos = indent = 0, len = s.length; pos < len; pos++) { ch = s.charCodeAt(pos); // TODO: check other spaces and tabs too or keep existing regexp replace ?? @@ -101,4 +101,4 @@ State.prototype.clone = function clone(src) { ); }; -module.exports = State; \ No newline at end of file +module.exports = State; diff --git a/package.json b/package.json index 56f899f..ca0cf06 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,10 @@ "ansi": "^0.3.0", "benchmark": "^1.0.0", "browserify": "*", + "eslint": "^0.8.0", + "eslint-plugin-nodeca": "^1.0.0", "jade": "1.6.0", - "jshint": "*", "mocha": "*", "uglifyjs": "*" } } - diff --git a/test/remarkable.js b/test/remarkable.js index 548c3cd..c54215c 100644 --- a/test/remarkable.js +++ b/test/remarkable.js @@ -13,4 +13,4 @@ describe('Default', function () { var md = new Remarked(); utils.addTests(path.join(__dirname, 'fixtures/remarkable'), md); -}); \ No newline at end of file +}); diff --git a/test/stmd.js b/test/stmd.js index 1ee6833..47dbd50 100644 --- a/test/stmd.js +++ b/test/stmd.js @@ -27,4 +27,4 @@ describe('stmd original with error', function () { var md = new Remarked(); utils.addTests(path.join(__dirname, 'fixtures/stmd_conflicting'), md, true); -}); \ No newline at end of file +}); diff --git a/test/utils.js b/test/utils.js index b32a63a..4f90654 100644 --- a/test/utils.js +++ b/test/utils.js @@ -32,7 +32,7 @@ function addTests(dir, md, skip) { ext = path.extname(name), base = path.basename(name, ext); - if (['.md', '.markdown'].indexOf(ext) !== -1) { + if ([ '.md', '.markdown' ].indexOf(ext) !== -1) { src = fixtures[name]; right = fixtures[base + '.html']; @@ -53,4 +53,4 @@ function addTests(dir, md, skip) { } -module.exports.addTests = addTests; \ No newline at end of file +module.exports.addTests = addTests;