From 94177fca7092c04c9eaa91f6817723076bff80b3 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Tue, 28 Nov 2023 06:14:12 +0200 Subject: [PATCH] standard: spaces in comments --- .eslintrc.yml | 5 ++++- benchmark/benchmark.mjs | 2 +- benchmark/profile.mjs | 2 +- bin/markdown-it.mjs | 5 +---- lib/common/utils.mjs | 18 ++++++------------ lib/index.mjs | 4 +--- lib/parser_inline.mjs | 2 -- lib/renderer.mjs | 1 - lib/ruler.mjs | 2 +- lib/rules_block/code.mjs | 2 +- lib/rules_block/lheading.mjs | 2 +- lib/rules_block/reference.mjs | 6 +++--- lib/rules_core/smartquotes.mjs | 4 ++-- lib/rules_inline/autolink.mjs | 2 +- lib/rules_inline/html_inline.mjs | 2 +- lib/rules_inline/text.mjs | 2 +- support/build_demo.mjs | 2 +- support/demo_template/index.mjs | 9 ++++----- support/specsplit.mjs | 6 +----- test/misc.mjs | 4 ++-- test/utils.mjs | 4 ++-- 21 files changed, 35 insertions(+), 51 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 4bdbff5..c832d21 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -153,7 +153,10 @@ rules: space-infix-ops: 2 space-unary-ops: 2 # Postponed - #spaced-comment: [ 1, always, { exceptions: [ '/', '=' ] } ] + spaced-comment: [ 2, 'always', { + line: { markers: ['*package', '!', '/', ',', '='] }, + block: { balanced: true, markers: ['*package', '!', ',', ':', '::', 'flow-include'], exceptions: ['*'] } + }] strict: [ 2, global ] quotes: [ 2, single, avoid-escape ] quote-props: [ 1, 'as-needed' ] diff --git a/benchmark/benchmark.mjs b/benchmark/benchmark.mjs index 69374bd..1345c24 100755 --- a/benchmark/benchmark.mjs +++ b/benchmark/benchmark.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -/*eslint no-console:0*/ +/* eslint no-console:0 */ import { createRequire } from 'node:module' const require = createRequire(import.meta.url) diff --git a/benchmark/profile.mjs b/benchmark/profile.mjs index 44a4066..eca9993 100755 --- a/benchmark/profile.mjs +++ b/benchmark/profile.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -/*eslint no-console:0*/ +/* eslint no-console:0 */ import { readFileSync } from 'fs' import markdownit from '../index.mjs' diff --git a/bin/markdown-it.mjs b/bin/markdown-it.mjs index 3b35de6..a53fa30 100755 --- a/bin/markdown-it.mjs +++ b/bin/markdown-it.mjs @@ -1,11 +1,10 @@ #!/usr/bin/env node -/*eslint no-console:0*/ +/* eslint no-console:0 */ import fs from 'node:fs' import argparse from 'argparse' import markdownit from '../index.mjs' -//////////////////////////////////////////////////////////////////////////////// const cli = new argparse.ArgumentParser({ prog: 'markdown-it', @@ -67,8 +66,6 @@ function readFile (filename, encoding, callback) { } -//////////////////////////////////////////////////////////////////////////////// - readFile(options.file, 'utf8', function (err, input) { let output diff --git a/lib/common/utils.mjs b/lib/common/utils.mjs index f4e5648..5bae0fa 100644 --- a/lib/common/utils.mjs +++ b/lib/common/utils.mjs @@ -18,7 +18,7 @@ function has (object, key) { // Merge objects // -function assign (obj /*from1, from2, from3, ...*/) { +function assign (obj /* from1, from2, from3, ... */) { const sources = Array.prototype.slice.call(arguments, 1) sources.forEach(function (source) { @@ -42,10 +42,9 @@ function arrayReplaceAt (src, pos, newElements) { return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)) } -//////////////////////////////////////////////////////////////////////////////// function isValidEntityCode (c) { - /*eslint no-bitwise:0*/ + /* eslint no-bitwise:0 */ // broken sequence if (c >= 0xD800 && c <= 0xDFFF) { return false } // never used @@ -62,7 +61,7 @@ function isValidEntityCode (c) { } function fromCodePoint (c) { - /*eslint no-bitwise:0*/ + /* eslint no-bitwise:0 */ if (c > 0xffff) { c -= 0x10000 const surrogate1 = 0xd800 + (c >> 10) @@ -101,11 +100,11 @@ function replaceEntityPattern (match, name) { return match } -/*function replaceEntities(str) { +/* function replaceEntities(str) { if (str.indexOf('&') < 0) { return str; } return str.replace(ENTITY_RE, replaceEntityPattern); -}*/ +} */ function unescapeMd (str) { if (str.indexOf('\\') < 0) { return str } @@ -121,7 +120,6 @@ function unescapeAll (str) { }) } -//////////////////////////////////////////////////////////////////////////////// const HTML_ESCAPE_TEST_RE = /[&<>"]/ const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g @@ -143,7 +141,6 @@ function escapeHtml (str) { return str } -//////////////////////////////////////////////////////////////////////////////// const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g @@ -151,7 +148,6 @@ function escapeRE (str) { return str.replace(REGEXP_ESCAPE_RE, '\\$&') } -//////////////////////////////////////////////////////////////////////////////// function isSpace (code) { switch (code) { @@ -182,9 +178,8 @@ function isWhiteSpace (code) { return false } -//////////////////////////////////////////////////////////////////////////////// -/*eslint-disable max-len*/ +/* eslint-disable max-len */ // Currently without astral characters support. function isPunctChar (ch) { @@ -291,7 +286,6 @@ function normalizeReference (str) { return str.toLowerCase().toUpperCase() } -//////////////////////////////////////////////////////////////////////////////// // Re-export libraries commonly used in both markdown-it and its plugins, // so plugins won't have to depend on them explicitly, which reduces their diff --git a/lib/index.mjs b/lib/index.mjs index c271fc8..13b50d2 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -20,7 +20,7 @@ const config = { commonmark: cfg_commonmark } -//////////////////////////////////////////////////////////////////////////////// + // // This validator can prohibit more than really needed to prevent XSS. It's a // tradeoff to keep code simple and to be secure by default. @@ -39,8 +39,6 @@ function validateLink (url) { return BAD_PROTO_RE.test(str) ? (GOOD_DATA_RE.test(str) ? true : false) : true } -//////////////////////////////////////////////////////////////////////////////// - const RECODE_HOSTNAME_FOR = ['http:', 'https:', 'mailto:'] diff --git a/lib/parser_inline.mjs b/lib/parser_inline.mjs index 4f282e7..cc3c337 100644 --- a/lib/parser_inline.mjs +++ b/lib/parser_inline.mjs @@ -24,8 +24,6 @@ import r_balance_pairs from './rules_inline/balance_pairs.mjs' import r_fragments_join from './rules_inline/fragments_join.mjs' - -//////////////////////////////////////////////////////////////////////////////// // Parser rules const _rules = [ diff --git a/lib/renderer.mjs b/lib/renderer.mjs index 7fe20fb..ff8c04b 100644 --- a/lib/renderer.mjs +++ b/lib/renderer.mjs @@ -8,7 +8,6 @@ import { assign, unescapeAll, escapeHtml } from './common/utils.mjs' -//////////////////////////////////////////////////////////////////////////////// const default_rules = {} diff --git a/lib/ruler.mjs b/lib/ruler.mjs index 375cf4e..cb30fdb 100644 --- a/lib/ruler.mjs +++ b/lib/ruler.mjs @@ -40,7 +40,7 @@ function Ruler () { this.__cache__ = null } -//////////////////////////////////////////////////////////////////////////////// + // Helper methods, should not be used directly diff --git a/lib/rules_block/code.mjs b/lib/rules_block/code.mjs index ae2897d..e45e6f9 100644 --- a/lib/rules_block/code.mjs +++ b/lib/rules_block/code.mjs @@ -1,6 +1,6 @@ // Code block (4 spaces padded) -export default function code (state, startLine, endLine/*, silent*/) { +export default function code (state, startLine, endLine/*, silent */) { if (state.sCount[startLine] - state.blkIndent < 4) { return false } let nextLine = startLine + 1 diff --git a/lib/rules_block/lheading.mjs b/lib/rules_block/lheading.mjs index 0ff177b..ee3b9a3 100644 --- a/lib/rules_block/lheading.mjs +++ b/lib/rules_block/lheading.mjs @@ -1,6 +1,6 @@ // lheading (---, ===) -export default function lheading (state, startLine, endLine/*, silent*/) { +export default function lheading (state, startLine, endLine/*, silent */) { const terminatorRules = state.md.block.ruler.getRules('paragraph') // if it's indented more than 3 spaces, it should be a code block diff --git a/lib/rules_block/reference.mjs b/lib/rules_block/reference.mjs index be65dda..4d699f4 100644 --- a/lib/rules_block/reference.mjs +++ b/lib/rules_block/reference.mjs @@ -80,7 +80,7 @@ export default function reference (state, startLine, _endLine, silent) { if (ch === 0x0A) { lines++ } else if (isSpace(ch)) { - /*eslint no-empty:0*/ + /* eslint no-empty:0 */ } else { break } @@ -109,7 +109,7 @@ export default function reference (state, startLine, _endLine, silent) { if (ch === 0x0A) { lines++ } else if (isSpace(ch)) { - /*eslint no-empty:0*/ + /* eslint no-empty:0 */ } else { break } @@ -164,7 +164,7 @@ export default function reference (state, startLine, _endLine, silent) { } // Reference can not terminate anything. This check is for safety only. - /*istanbul ignore if*/ + /* istanbul ignore if */ if (silent) { return true } if (typeof state.env.references === 'undefined') { diff --git a/lib/rules_core/smartquotes.mjs b/lib/rules_core/smartquotes.mjs index a3a436d..8426e71 100644 --- a/lib/rules_core/smartquotes.mjs +++ b/lib/rules_core/smartquotes.mjs @@ -33,7 +33,7 @@ function process_inlines (tokens, state) { let pos = 0 let max = text.length - /*eslint no-labels:0,block-scoped-var:0*/ + /* eslint no-labels:0,block-scoped-var:0 */ OUTER: while (pos < max) { QUOTE_RE.lastIndex = pos @@ -181,7 +181,7 @@ function process_inlines (tokens, state) { export default function smartquotes (state) { - /*eslint max-depth:0*/ + /* eslint max-depth:0 */ if (!state.md.options.typographer) { return } for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { diff --git a/lib/rules_inline/autolink.mjs b/lib/rules_inline/autolink.mjs index d9e34a1..b38c89d 100644 --- a/lib/rules_inline/autolink.mjs +++ b/lib/rules_inline/autolink.mjs @@ -1,6 +1,6 @@ // Process autolinks '' -/*eslint max-len:0*/ +/* eslint max-len:0 */ const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/ const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/ diff --git a/lib/rules_inline/html_inline.mjs b/lib/rules_inline/html_inline.mjs index 7eaabb2..f89b54f 100644 --- a/lib/rules_inline/html_inline.mjs +++ b/lib/rules_inline/html_inline.mjs @@ -12,7 +12,7 @@ function isLinkClose (str) { function isLetter (ch) { - /*eslint no-bitwise:0*/ + /* eslint no-bitwise:0 */ const lc = ch | 0x20 // to lower case return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */) } diff --git a/lib/rules_inline/text.mjs b/lib/rules_inline/text.mjs index 2b50abc..1b88c5a 100644 --- a/lib/rules_inline/text.mjs +++ b/lib/rules_inline/text.mjs @@ -83,4 +83,4 @@ module.exports = function text(state, silent) { state.pos += idx; return true; -};*/ +}; */ diff --git a/support/build_demo.mjs b/support/build_demo.mjs index 5d11869..4024570 100644 --- a/support/build_demo.mjs +++ b/support/build_demo.mjs @@ -9,7 +9,7 @@ function escape (input) { .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') - //.replaceAll("'", '''); + // .replaceAll("'", '''); } shell.rm('-rf', 'demo') diff --git a/support/demo_template/index.mjs b/support/demo_template/index.mjs index 44b69bb..b40704a 100644 --- a/support/demo_template/index.mjs +++ b/support/demo_template/index.mjs @@ -1,5 +1,5 @@ -/*eslint-env browser*/ -/*global $, _*/ +/* eslint-env browser */ +/* global $, _ */ import mdurl from 'mdurl' import hljs from 'highlight.js' @@ -50,7 +50,7 @@ defaults.highlight = function (str, lang) { const result = hljs.highlightAuto(str) - /*eslint-disable no-console*/ + /* eslint-disable no-console */ console.log('highlight language: ' + result.language + ', relevance: ' + result.relevance) return '
' +
@@ -156,7 +156,7 @@ function updateResult () {
       'json'
     )
 
-  } else { /*defaults._view === 'html'*/
+  } else { /* defaults._view === 'html' */
     $('.result-html').html(mdHtml.render(source))
   }
 
@@ -349,7 +349,6 @@ function loadPermalink () {
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
 // Init on page load
 //
 $(function () {
diff --git a/support/specsplit.mjs b/support/specsplit.mjs
index 7b017ae..2e386e2 100755
--- a/support/specsplit.mjs
+++ b/support/specsplit.mjs
@@ -1,5 +1,5 @@
 #!/usr/bin/env node
-/*eslint no-console:0*/
+/* eslint no-console:0 */
 
 // Fixtures generator from commonmark specs. Split spec to working / not working
 // examples, or show total stat.
@@ -31,13 +31,11 @@ cli.add_argument('-o', '--output', {
 
 const options = cli.parse_args()
 
-////////////////////////////////////////////////////////////////////////////////
 
 function normalize (text) {
   return text.replace(/
\n<\/blockquote>/g, '
') } -//////////////////////////////////////////////////////////////////////////////// function readFile (filename, encoding, callback) { if (options.file === '-') { @@ -58,8 +56,6 @@ function readFile (filename, encoding, callback) { } -//////////////////////////////////////////////////////////////////////////////// - readFile(options.spec, 'utf8', function (error, input) { const good = [] const bad = [] diff --git a/test/misc.mjs b/test/misc.mjs index a9376b6..67aef87 100644 --- a/test/misc.mjs +++ b/test/misc.mjs @@ -182,7 +182,7 @@ describe('Plugins', function () { it('should not loop infinitely if inline rule doesn\'t increment pos', function () { const md = markdownit() - md.inline.ruler.after('text', 'custom', function (state/*, silent*/) { + md.inline.ruler.after('text', 'custom', function (state/*, silent */) { if (state.src.charCodeAt(state.pos) !== 0x40/* @ */) return false return true }) @@ -194,7 +194,7 @@ describe('Plugins', function () { it('should not loop infinitely if block rule doesn\'t increment pos', function () { const md = markdownit() - md.block.ruler.before('paragraph', 'custom', function (state, startLine/*, endLine, silent*/) { + md.block.ruler.before('paragraph', 'custom', function (state, startLine/*, endLine, silent */) { const pos = state.bMarks[startLine] + state.tShift[startLine] if (state.src.charCodeAt(pos) !== 0x40/* @ */) return false return true diff --git a/test/utils.mjs b/test/utils.mjs index 46e826d..5e2fb46 100644 --- a/test/utils.mjs +++ b/test/utils.mjs @@ -25,7 +25,7 @@ describe('Utils', function () { assert.strictEqual(isValidEntityCode(0x7F), false) }) - /*it('replaceEntities', function () { + /* it('replaceEntities', function () { var replaceEntities = utils.replaceEntities; assert.strictEqual(replaceEntities('&'), '&'); @@ -35,7 +35,7 @@ describe('Utils', function () { assert.strictEqual(replaceEntities('&am;'), '&am;'); assert.strictEqual(replaceEntities('�'), '�'); - });*/ + }); */ it('assign', function () { const assign = utils.assign