Skip to content

Commit

Permalink
separate eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 4, 2019
1 parent 83d2596 commit d9f22d2
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 27 deletions.
146 changes: 139 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": "standard",
"plugins": [
"standard"
],
"parserOptions": { "ecmaVersion": 5 },
"rules": {
"semi": ["error", "always"],
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion bin/marked
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals marked, unfetch, ES6Promise */
/* globals marked, unfetch, ES6Promise, Promise */

if (!window.Promise) {
window.Promise = ES6Promise;
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/worker.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
28 changes: 28 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 2 additions & 2 deletions test/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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$/)) {
Expand Down Expand Up @@ -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':
Expand Down
26 changes: 13 additions & 13 deletions test/unit/marked-spec.js
Original file line number Diff line number Diff line change
@@ -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('<h1 id="test">test</h1>\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('<h1>test</h1>\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');
Expand All @@ -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');
});
});
Expand Down

0 comments on commit d9f22d2

Please sign in to comment.