From d9f22d2726d5e0ca195f66c8a37f61046cb6a263 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 25 Apr 2019 13:07:58 -0500 Subject: [PATCH] separate eslint config --- .eslintrc.json | 146 +++++++++++++++++++++++++++++++++++++-- bin/marked | 2 +- docs/demo/demo.js | 2 +- docs/demo/worker.js | 2 +- lib/marked.js | 4 +- test/.eslintrc.json | 28 ++++++++ test/bench.js | 4 +- test/unit/marked-spec.js | 26 +++---- 8 files changed, 187 insertions(+), 27 deletions(-) create mode 100644 test/.eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json index 1800cb721a..fea5455ab1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,4 @@ { - "extends": "standard", - "plugins": [ - "standard" - ], "parserOptions": { "ecmaVersion": 5 }, "rules": { "semi": ["error", "always"], @@ -18,12 +14,148 @@ "no-useless-escape": "off", "no-return-assign": "off", "one-var": "off", - "no-control-regex": "off" + "no-control-regex": "off", + + "accessor-pairs": "error", + "arrow-spacing": ["error", { "before": true, "after": true }], + "block-spacing": ["error", "always"], + "brace-style": ["error", "1tbs", { "allowSingleLine": true }], + "camelcase": ["error", { "properties": "never" }], + "comma-dangle": ["error", { + "arrays": "never", + "objects": "never", + "imports": "never", + "exports": "never", + "functions": "never" + }], + "comma-spacing": ["error", { "before": false, "after": true }], + "comma-style": ["error", "last"], + "constructor-super": "error", + "curly": ["error", "multi-line"], + "dot-location": ["error", "property"], + "eol-last": "error", + "eqeqeq": ["error", "always", { "null": "ignore" }], + "func-call-spacing": ["error", "never"], + "generator-star-spacing": ["error", { "before": true, "after": true }], + "handle-callback-err": ["error", "^(err|error)$" ], + "key-spacing": ["error", { "beforeColon": false, "afterColon": true }], + "keyword-spacing": ["error", { "before": true, "after": true }], + "new-cap": ["error", { "newIsCap": true, "capIsNew": false }], + "new-parens": "error", + "no-array-constructor": "error", + "no-caller": "error", + "no-class-assign": "error", + "no-compare-neg-zero": "error", + "no-const-assign": "error", + "no-constant-condition": ["error", { "checkLoops": false }], + "no-debugger": "error", + "no-delete-var": "error", + "no-dupe-args": "error", + "no-dupe-class-members": "error", + "no-dupe-keys": "error", + "no-duplicate-case": "error", + "no-empty-character-class": "error", + "no-empty-pattern": "error", + "no-eval": "error", + "no-ex-assign": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-boolean-cast": "error", + "no-extra-parens": ["error", "functions"], + "no-fallthrough": "error", + "no-floating-decimal": "error", + "no-func-assign": "error", + "no-global-assign": "error", + "no-implied-eval": "error", + "no-inner-declarations": ["error", "functions"], + "no-invalid-regexp": "error", + "no-irregular-whitespace": "error", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": ["error", { "allowLoop": false, "allowSwitch": false }], + "no-lone-blocks": "error", + "no-mixed-operators": ["error", { + "groups": [ + ["==", "!=", "===", "!==", ">", ">=", "<", "<="], + ["&&", "||"], + ["in", "instanceof"] + ], + "allowSamePrecedence": true + }], + "no-mixed-spaces-and-tabs": "error", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }], + "no-negated-in-lhs": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-object": "error", + "no-new-require": "error", + "no-new-symbol": "error", + "no-new-wrappers": "error", + "no-obj-calls": "error", + "no-octal": "error", + "no-octal-escape": "error", + "no-path-concat": "error", + "no-proto": "error", + "no-redeclare": "error", + "no-regex-spaces": "error", + "no-return-await": "error", + "no-self-assign": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-shadow-restricted-names": "error", + "no-sparse-arrays": "error", + "no-tabs": "error", + "no-template-curly-in-string": "error", + "no-this-before-super": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef": "error", + "no-undef-init": "error", + "no-unexpected-multiline": "error", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": ["error", { "defaultAssignment": false }], + "no-unreachable": "error", + "no-unsafe-finally": "error", + "no-unsafe-negation": "error", + "no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }], + "no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }], + "no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }], + "no-useless-call": "error", + "no-useless-computed-key": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-whitespace-before-property": "error", + "no-with": "error", + "object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }], + "padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }], + "prefer-promise-reject-errors": "error", + "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }], + "rest-spread-spacing": ["error", "never"], + "semi-spacing": ["error", { "before": false, "after": true }], + "space-before-blocks": ["error", "always"], + "space-in-parens": ["error", "never"], + "space-infix-ops": "error", + "space-unary-ops": ["error", { "words": true, "nonwords": false }], + "spaced-comment": ["error", "always", { + "line": { "markers": ["*package", "!", "/", ",", "="] }, + "block": { "balanced": true, "markers": ["*package", "!", ",", ":", "::", "flow-include"], "exceptions": ["*"] } + }], + "symbol-description": "error", + "template-curly-spacing": ["error", "never"], + "template-tag-spacing": ["error", "never"], + "unicode-bom": ["error", "never"], + "use-isnan": "error", + "valid-typeof": ["error", { "requireStringLiterals": true }], + "wrap-iife": ["error", "any", { "functionPrototypeMethods": true }], + "yield-star-spacing": ["error", "both"], + "yoda": ["error", "never"] }, "env": { "node": true, "browser": true, - "amd": true, - "jasmine": true + "amd": true } } diff --git a/bin/marked b/bin/marked index 0ea63c540b..307db173b0 100755 --- a/bin/marked +++ b/bin/marked @@ -194,7 +194,7 @@ function camelize(text) { function handleError(err) { if (err.code === 'ENOENT') { - console.error(`marked: output to ${err.path}: No such directory`); + console.error('marked: output to ' + err.path + ': No such directory'); return process.exit(1); } throw err; diff --git a/docs/demo/demo.js b/docs/demo/demo.js index e7d97c59bd..a478de4c7c 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -1,4 +1,4 @@ -/* globals marked, unfetch, ES6Promise */ +/* globals marked, unfetch, ES6Promise, Promise */ if (!window.Promise) { window.Promise = ES6Promise; diff --git a/docs/demo/worker.js b/docs/demo/worker.js index 06b8befe78..bdd7addf7f 100644 --- a/docs/demo/worker.js +++ b/docs/demo/worker.js @@ -1,4 +1,4 @@ -/* globals marked, unfetch, ES6Promise */ +/* globals marked, unfetch, ES6Promise, Promise */ if (!self.Promise) { self.importScripts('https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js'); self.Promise = ES6Promise; diff --git a/lib/marked.js b/lib/marked.js index a4b24c426e..6a9d1494af 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -217,11 +217,11 @@ Lexer.prototype.token = function(src, top) { // code if (cap = this.rules.code.exec(src)) { - const lastToken = this.tokens[this.tokens.length - 1]; + var lastToken = this.tokens[this.tokens.length - 1]; src = src.substring(cap[0].length); // An indented code block cannot interrupt a paragraph. if (lastToken && lastToken.type === 'paragraph') { - lastToken.text += `\n${cap[0].trimRight()}`; + lastToken.text += '\n' + cap[0].trimRight(); } else { cap = cap[0].replace(/^ {4}/gm, ''); this.tokens.push({ diff --git a/test/.eslintrc.json b/test/.eslintrc.json new file mode 100644 index 0000000000..3c9cc1ec59 --- /dev/null +++ b/test/.eslintrc.json @@ -0,0 +1,28 @@ +{ + "extends": "standard", + "plugins": [ + "standard" + ], + "parserOptions": { "ecmaVersion": 2018 }, + "rules": { + "semi": ["error", "always"], + "indent": ["warn", 2, { + "SwitchCase": 1, + "outerIIFEBody": 0 + }], + "space-before-function-paren": "off", + "object-curly-spacing": "off", + "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], + "no-cond-assign": "off", + "no-useless-escape": "off", + "no-return-assign": "off", + "one-var": "off", + "no-control-regex": "off", + "prefer-const": "error", + "no-var": "error" + }, + "env": { + "node": true, + "jasmine": true + } +} diff --git a/test/bench.js b/test/bench.js index ebada7073f..d435a72f83 100644 --- a/test/bench.js +++ b/test/bench.js @@ -7,7 +7,7 @@ const htmlDiffer = require('./helpers/html-differ.js'); let marked = require('../'); function load() { - let folder = path.resolve(__dirname, './specs/commonmark'); + const folder = path.resolve(__dirname, './specs/commonmark'); const files = fs.readdirSync(folder); return files.reduce((arr, file) => { if (file.match(/\.json$/)) { @@ -171,7 +171,7 @@ function parseArg(argv) { const defaults = marked.getDefaults(); while (argv.length) { - let arg = getarg(); + const arg = getarg(); switch (arg) { case '-t': case '--time': diff --git a/test/unit/marked-spec.js b/test/unit/marked-spec.js index 994c5dc8d7..e28371aa47 100644 --- a/test/unit/marked-spec.js +++ b/test/unit/marked-spec.js @@ -1,42 +1,42 @@ -var marked = require('../../lib/marked.js'); +const marked = require('../../lib/marked.js'); describe('Test heading ID functionality', () => { it('should add id attribute by default', () => { - var renderer = new marked.Renderer(); - var slugger = new marked.Slugger(); - var header = renderer.heading('test', 1, 'test', slugger); + const renderer = new marked.Renderer(); + const slugger = new marked.Slugger(); + const header = renderer.heading('test', 1, 'test', slugger); expect(header).toBe('

test

\n'); }); it('should NOT add id attribute when options set false', () => { - var renderer = new marked.Renderer({ headerIds: false }); - var header = renderer.heading('test', 1, 'test'); + const renderer = new marked.Renderer({ headerIds: false }); + const header = renderer.heading('test', 1, 'test'); expect(header).toBe('

test

\n'); }); }); describe('Test slugger functionality', () => { it('should use lowercase slug', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('Test')).toBe('test'); }); it('should be unique to avoid collisions 1280', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('test')).toBe('test'); expect(slugger.slug('test')).toBe('test-1'); expect(slugger.slug('test')).toBe('test-2'); }); it('should be unique when slug ends with number', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('test 1')).toBe('test-1'); expect(slugger.slug('test')).toBe('test'); expect(slugger.slug('test')).toBe('test-2'); }); it('should be unique when slug ends with hyphen number', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('foo')).toBe('foo'); expect(slugger.slug('foo')).toBe('foo-1'); expect(slugger.slug('foo 1')).toBe('foo-1-1'); @@ -45,17 +45,17 @@ describe('Test slugger functionality', () => { }); it('should allow non-latin chars', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('привет')).toBe('привет'); }); it('should remove ampersands 857', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('This & That Section')).toBe('this--that-section'); }); it('should remove periods', () => { - var slugger = new marked.Slugger(); + const slugger = new marked.Slugger(); expect(slugger.slug('file.txt')).toBe('filetxt'); }); });