Skip to content

Commit 0f3fc89

Browse files
committed
(chore) fix some linter unhappiness
1 parent 88514b7 commit 0f3fc89

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

Diff for: .eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ module.exports = {
2929
quotes: "off",
3030
// this is the style we are already using
3131
"operator-linebreak": ["error", "before", { overrides: {
32-
"=": "after",
33-
"+": "after"
32+
"=": "after"
3433
}
3534
}],
3635
// sometimes we declare variables with extra spacing

Diff for: src/highlight.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as logger from "./lib/logger.js";
1717
/**
1818
@typedef {import('highlight.js').Mode} Mode
1919
@typedef {import('highlight.js').CompiledMode} CompiledMode
20+
@typedef {import('highlight.js').CompiledScope} CompiledScope
2021
@typedef {import('highlight.js').Language} Language
2122
@typedef {import('highlight.js').HLJSApi} HLJSApi
2223
@typedef {import('highlight.js').HLJSPlugin} HLJSPlugin
@@ -269,7 +270,7 @@ const HLJS = function(hljs) {
269270
}
270271

271272
/**
272-
* @param {CompiledMode} mode
273+
* @param {CompiledScope} scope
273274
* @param {RegExpMatchArray} match
274275
*/
275276
function emitMultiClass(scope, match) {

Diff for: src/lib/ext/multi_class.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const MultiClassError = new Error();
3333
* are 1, 2, and 5. This function handles this behavior.
3434
*
3535
* @param {CompiledMode} mode
36-
* @param {Array<RegExp>} regexes
36+
* @param {Array<RegExp | string>} regexes
3737
* @param {{key: "beginScope"|"endScope"}} opts
3838
*/
3939
function remapScopeNames(mode, regexes, { key }) {
@@ -72,7 +72,7 @@ function beginMultiClass(mode) {
7272
throw MultiClassError;
7373
}
7474

75-
remapScopeNames(mode, mode.begin, {key: "beginScope"});
75+
remapScopeNames(mode, mode.begin, { key: "beginScope" });
7676
mode.begin = regex._rewriteBackreferences(mode.begin, { joinWith: "" });
7777
}
7878

@@ -92,7 +92,7 @@ function endMultiClass(mode) {
9292
throw MultiClassError;
9393
}
9494

95-
remapScopeNames(mode, mode.end, {key: "endScope"});
95+
remapScopeNames(mode, mode.end, { key: "endScope" });
9696
mode.end = regex._rewriteBackreferences(mode.end, { joinWith: "" });
9797
}
9898

Diff for: src/lib/mode_compiler.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export function compileLanguage(language) {
3333
function langRe(value, global) {
3434
return new RegExp(
3535
regex.source(value),
36-
'm' + (language.case_insensitive ? 'i' : '') + (language.unicodeRegex ? 'u' : '') + (global ? 'g' : '')
36+
'm'
37+
+ (language.case_insensitive ? 'i' : '')
38+
+ (language.unicodeRegex ? 'u' : '')
39+
+ (global ? 'g' : '')
3740
);
3841
}
3942

@@ -334,10 +337,10 @@ export function compileLanguage(language) {
334337

335338
if (parent) {
336339
if (!mode.begin) mode.begin = /\B|\b/;
337-
cmode.beginRe = langRe(mode.begin);
340+
cmode.beginRe = langRe(cmode.begin);
338341
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
339-
if (mode.end) cmode.endRe = langRe(mode.end);
340-
cmode.terminatorEnd = regex.source(mode.end) || '';
342+
if (mode.end) cmode.endRe = langRe(cmode.end);
343+
cmode.terminatorEnd = regex.source(cmode.end) || '';
341344
if (mode.endsWithParent && parent.terminatorEnd) {
342345
cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
343346
}

Diff for: src/lib/regex.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export function concat(...args) {
5050
return joined;
5151
}
5252

53+
/**
54+
* @param { Array<string | RegExp | Object> } args
55+
* @returns {object}
56+
*/
5357
function stripOptionsFromArgs(args) {
5458
const opts = args[args.length - 1];
5559

@@ -69,15 +73,16 @@ function stripOptionsFromArgs(args) {
6973
* @returns {string}
7074
*/
7175
export function either(...args) {
76+
/** @type { object & {capture?: boolean} } */
7277
const opts = stripOptionsFromArgs(args);
73-
const joined = '(' +
74-
(opts.capture ? "" : "?:") +
75-
args.map((x) => source(x)).join("|") + ")";
78+
const joined = '('
79+
+ (opts.capture ? "" : "?:")
80+
+ args.map((x) => source(x)).join("|") + ")";
7681
return joined;
7782
}
7883

7984
/**
80-
* @param {RegExp} re
85+
* @param {RegExp | string} re
8186
* @returns {number}
8287
*/
8388
export function countMatchGroups(re) {

Diff for: types/index.d.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare module 'highlight.js/private' {
1515
}
1616
declare module 'highlight.js' {
1717

18-
import { KeywordDict} from "highlight.js/private";
18+
import { KeywordDict } from "highlight.js/private";
1919

2020
export type HLJSApi = PublicApi & ModesAPI
2121

@@ -190,8 +190,13 @@ declare module 'highlight.js' {
190190
keywords: Record<string, any>
191191
}
192192

193+
export type CompiledScope = Record<number, string> & {_emit?: Record<number, boolean>, _multi?: boolean, _wrap?: string};
194+
193195
export type CompiledMode = Omit<Mode, 'contains'> &
194196
{
197+
begin?: RegExp | string
198+
end?: RegExp | string
199+
scope?: string
195200
contains: CompiledMode[]
196201
keywords: KeywordDict
197202
data: Record<string, any>
@@ -204,8 +209,8 @@ declare module 'highlight.js' {
204209
isCompiled: true
205210
starts?: CompiledMode
206211
parent?: CompiledMode
207-
beginScope?: Record<number, string> & {_emit?: Record<number,boolean>, _multi?: boolean, _wrap?: string}
208-
endScope?: Record<number, string> & {_emit?: Record<number,boolean>, _multi?: boolean, _wrap?: string}
212+
beginScope?: CompiledScope
213+
endScope?: CompiledScope
209214
}
210215

211216
interface ModeDetails {

0 commit comments

Comments
 (0)