Skip to content

Commit

Permalink
standard: spaces in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
puzrin committed Nov 28, 2023
1 parent 9e73787 commit 94177fc
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.mjs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/profile.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
5 changes: 1 addition & 4 deletions bin/markdown-it.mjs
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -67,8 +66,6 @@ function readFile (filename, encoding, callback) {
}


////////////////////////////////////////////////////////////////////////////////

readFile(options.file, 'utf8', function (err, input) {
let output

Expand Down
18 changes: 6 additions & 12 deletions lib/common/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 }
Expand All @@ -121,7 +120,6 @@ function unescapeAll (str) {
})
}

////////////////////////////////////////////////////////////////////////////////

const HTML_ESCAPE_TEST_RE = /[&<>"]/
const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g
Expand All @@ -143,15 +141,13 @@ function escapeHtml (str) {
return str
}

////////////////////////////////////////////////////////////////////////////////

const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g

function escapeRE (str) {
return str.replace(REGEXP_ESCAPE_RE, '\\$&')
}

////////////////////////////////////////////////////////////////////////////////

function isSpace (code) {
switch (code) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:']

Expand Down
2 changes: 0 additions & 2 deletions lib/parser_inline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 0 additions & 1 deletion lib/renderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { assign, unescapeAll, escapeHtml } from './common/utils.mjs'

////////////////////////////////////////////////////////////////////////////////

const default_rules = {}

Expand Down
2 changes: 1 addition & 1 deletion lib/ruler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function Ruler () {
this.__cache__ = null
}

////////////////////////////////////////////////////////////////////////////////

// Helper methods, should not be used directly


Expand Down
2 changes: 1 addition & 1 deletion lib/rules_block/code.mjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rules_block/lheading.mjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/rules_block/reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules_core/smartquotes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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--) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules_inline/autolink.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Process autolinks '<protocol:...>'

/*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]*)$/

Expand Down
2 changes: 1 addition & 1 deletion lib/rules_inline/html_inline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules_inline/text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ module.exports = function text(state, silent) {
state.pos += idx;
return true;
};*/
}; */
2 changes: 1 addition & 1 deletion support/build_demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function escape (input) {
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
//.replaceAll("'", '&#039;');
// .replaceAll("'", '&#039;');
}

shell.rm('-rf', 'demo')
Expand Down
9 changes: 4 additions & 5 deletions support/demo_template/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*eslint-env browser*/
/*global $, _*/
/* eslint-env browser */
/* global $, _ */

import mdurl from 'mdurl'
import hljs from 'highlight.js'
Expand Down Expand Up @@ -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 '<pre class="hljs language-' + esc(result.language) + '"><code>' +
Expand Down Expand Up @@ -156,7 +156,7 @@ function updateResult () {
'json'
)

} else { /*defaults._view === 'html'*/
} else { /* defaults._view === 'html' */
$('.result-html').html(mdHtml.render(source))
}

Expand Down Expand Up @@ -349,7 +349,6 @@ function loadPermalink () {
}


//////////////////////////////////////////////////////////////////////////////
// Init on page load
//
$(function () {
Expand Down
6 changes: 1 addition & 5 deletions support/specsplit.mjs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -31,13 +31,11 @@ cli.add_argument('-o', '--output', {

const options = cli.parse_args()

////////////////////////////////////////////////////////////////////////////////

function normalize (text) {
return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}

////////////////////////////////////////////////////////////////////////////////

function readFile (filename, encoding, callback) {
if (options.file === '-') {
Expand All @@ -58,8 +56,6 @@ function readFile (filename, encoding, callback) {
}


////////////////////////////////////////////////////////////////////////////////

readFile(options.spec, 'utf8', function (error, input) {
const good = []
const bad = []
Expand Down
4 changes: 2 additions & 2 deletions test/misc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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('&amp;'), '&');
Expand All @@ -35,7 +35,7 @@ describe('Utils', function () {
assert.strictEqual(replaceEntities('&am;'), '&am;');
assert.strictEqual(replaceEntities('&#00;'), '&#00;');
});*/
}); */

it('assign', function () {
const assign = utils.assign
Expand Down

0 comments on commit 94177fc

Please sign in to comment.