Skip to content

Commit e68a4bd

Browse files
Run Prettier on plugins + remove .prettierignore + tweak VS Code settings (#3983)
1 parent db0b5d9 commit e68a4bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1122
-745
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"editor.formatOnSave": true,
3+
"editor.formatOnSaveMode": "file",
34
"editor.defaultFormatter": "esbenp.prettier-vscode",
45
"prettier.enable": true
56
}

package-lock.json

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
"mocha-chai-jest-snapshot": "^1.1.6",
9797
"npm-run-all": "^4.1.5",
9898
"prettier": "^3.5.3",
99-
"prettier-plugin-brace-style": "^0.7.2",
100-
"prettier-plugin-merge": "^0.7.3",
99+
"prettier-plugin-brace-style": "^0.7.3",
100+
"prettier-plugin-merge": "^0.7.4",
101101
"prettier-plugin-space-before-function-paren": "^0.0.8",
102102
"refa": "^0.9.1",
103103
"regexp-ast-analysis": "^0.5.1",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.token a {
22
color: inherit;
3-
}
3+
}

src/plugins/autolinker/prism-autolinker.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ import type { PluginProto } from '../../types';
44
export default {
55
id: 'autolinker',
66
optional: 'diff-highlight',
7-
effect(Prism) {
8-
function balanced(chars: string) {
7+
effect (Prism) {
8+
function balanced (chars: string) {
99
return String.raw`(?:${chars}|\((?:${chars})*\))`;
1010
}
1111

1212
const url = RegExp(
13-
/\b(?:[a-z]{3,7}:\/\/|tel:)/.source
14-
+ `${balanced(/[\w\-+%~/.:=&!$'*,;@]/.source)}+`
15-
+ `(?:\\?${balanced(/[\w\-+%~/.:=&!$'*,;@?]/.source)}*)?`
16-
+ `(?:#${balanced(/[\w\-+%~/.:=&!$'*,;@?#]/.source)}*)?`
13+
/\b(?:[a-z]{3,7}:\/\/|tel:)/.source +
14+
`${balanced(/[\w\-+%~/.:=&!$'*,;@]/.source)}+` +
15+
`(?:\\?${balanced(/[\w\-+%~/.:=&!$'*,;@?]/.source)}*)?` +
16+
`(?:#${balanced(/[\w\-+%~/.:=&!$'*,;@?#]/.source)}*)?`
1717
);
1818
const email = /\b\S+@[\w.]+[a-z]{2}/;
1919

2020
const links = {
2121
'url-link': url,
22-
'email-link': email
22+
'email-link': email,
2323
};
2424

2525
return Prism.hooks.add({
26-
'after-tokenize': (env) => {
27-
tokenizeStrings(env.tokens, (code) => Prism.tokenize(code, links));
26+
'after-tokenize': env => {
27+
tokenizeStrings(env.tokens, code => Prism.tokenize(code, links));
2828
},
29-
'wrap': (env) => {
29+
'wrap': env => {
3030
if (env.type.endsWith('-link')) {
3131
let href = env.content;
3232

@@ -37,7 +37,7 @@ export default {
3737
env.tag = 'a';
3838
env.attributes.href = href;
3939
}
40-
}
40+
},
4141
});
42-
}
42+
},
4343
} as PluginProto<'autolinker'>;

src/plugins/autoloader/prism-autoloader.ts

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ import { toArray } from '../../util/iterables';
44
import type { Prism } from '../../core';
55
import type { ComponentProto, PluginProto } from '../../types';
66

7-
function getDefaultSrcPath() {
7+
function getDefaultSrcPath () {
88
if (typeof document !== 'undefined') {
99
const script = document.currentScript as HTMLScriptElement | null;
1010
if (script) {
11-
const autoloaderFile = /\bplugins\/autoloader\/prism-autoloader\.(?:min\.)?js(?:\?[^\r\n/]*)?$/i;
11+
const autoloaderFile =
12+
/\bplugins\/autoloader\/prism-autoloader\.(?:min\.)?js(?:\?[^\r\n/]*)?$/i;
1213
const prismFile = /(^|\/)[\w-]+\.(?:min\.)?m?js(?:\?[^\r\n/]*)?$/i;
1314

1415
const autoloaderPath = script.getAttribute('data-autoloader-path');
1516
if (autoloaderPath != null) {
1617
// data-autoloader-path is set, so just use it
1718
return autoloaderPath.trim().replace(/\/?$/, '/');
18-
} else {
19+
}
20+
else {
1921
const src = script.src;
2022
if (autoloaderFile.test(src)) {
2123
// the script is the original autoloader script in the usual Prism project structure
2224
return src.replace(autoloaderFile, '/');
23-
} else if (prismFile.test(src)) {
25+
}
26+
else if (prismFile.test(src)) {
2427
// the script is part of a bundle like a custom prism.js from the download page
2528
return src.replace(prismFile, '$1/');
2629
}
@@ -31,7 +34,7 @@ function getDefaultSrcPath() {
3134
return './';
3235
}
3336

34-
function pathJoin(dir: string, file: string) {
37+
function pathJoin (dir: string, file: string) {
3538
return dir.replace(/\/$/, '') + '/' + file;
3639
}
3740

@@ -41,7 +44,7 @@ const ignoredLanguages: ReadonlySet<string> = new Set(['none']);
4144
* @param Prism The Prism instance
4245
* @param name The name of the language
4346
*/
44-
function isLoaded(Prism: Prism, name: string) {
47+
function isLoaded (Prism: Prism, name: string) {
4548
// resolve alias
4649
const id = resolveAlias(name);
4750
return Prism.components.has(id) || ignoredLanguages.has(id);
@@ -56,56 +59,60 @@ export class Autoloader {
5659
/**
5760
* @package
5861
*/
59-
constructor(Prism: Prism) {
62+
constructor (Prism: Prism) {
6063
this.Prism = Prism;
6164
}
6265

6366
/**
6467
* Loads all given languages concurrently.
6568
*/
66-
async loadLanguages(languages: string | readonly string[]): Promise<void> {
69+
async loadLanguages (languages: string | readonly string[]): Promise<void> {
6770
const toLoad = toArray(languages)
6871
.map(resolveAlias)
69-
.filter((id) => !isLoaded(this.Prism, id));
70-
71-
await Promise.all(toLoad.map((id) => {
72-
const path = pathJoin(this.srcPath, `languages/${id}.js`);
73-
74-
let promise = this._importCache.get(path);
75-
if (promise === undefined) {
76-
promise = import(path).then((exports) => {
77-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
78-
const proto = exports.default as ComponentProto;
79-
this.Prism.components.add(proto);
80-
});
81-
this._importCache.set(path, promise);
82-
}
83-
return promise;
84-
}));
72+
.filter(id => !isLoaded(this.Prism, id));
73+
74+
await Promise.all(
75+
toLoad.map(id => {
76+
const path = pathJoin(this.srcPath, `languages/${id}.js`);
77+
78+
let promise = this._importCache.get(path);
79+
if (promise === undefined) {
80+
promise = import(path).then(exports => {
81+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
82+
const proto = exports.default as ComponentProto;
83+
this.Prism.components.add(proto);
84+
});
85+
this._importCache.set(path, promise);
86+
}
87+
return promise;
88+
})
89+
);
8590
}
8691

8792
/**
8893
* Loads all given languages concurrently.
8994
*
9095
* This function simply invokes {@link Autoloader#loadLanguages} and logs errors to `console.error`.
9196
*/
92-
preloadLanguages(languages: string | readonly string[]): void {
93-
this.loadLanguages(languages).catch((reason) => {
94-
console.error(`Failed to preload languages (${toArray(languages).join(', ')}): ${String(reason)}`);
97+
preloadLanguages (languages: string | readonly string[]): void {
98+
this.loadLanguages(languages).catch(reason => {
99+
console.error(
100+
`Failed to preload languages (${toArray(languages).join(', ')}): ${String(reason)}`
101+
);
95102
});
96103
}
97104
}
98105

99106
export default {
100107
id: 'autoloader',
101-
plugin(Prism) {
108+
plugin (Prism) {
102109
return new Autoloader(Prism);
103110
},
104-
effect(Prism) {
111+
effect (Prism) {
105112
/**
106113
* Returns all additional dependencies of the given element defined by the `data-dependencies` attribute.
107114
*/
108-
function getDependencies(element: Element) {
115+
function getDependencies (element: Element) {
109116
let deps = element.getAttribute('data-dependencies')?.trim();
110117
if (!deps) {
111118
const parent = getParentPre(element);
@@ -119,13 +126,15 @@ export default {
119126
/**
120127
* Maps the given name to a list of components that have to be loaded.
121128
*/
122-
function mapDependency(name: string) {
129+
function mapDependency (name: string) {
123130
if (!name || ignoredLanguages.has(name)) {
124131
return [];
125-
} else if (/^diff-./i.test(name)) {
132+
}
133+
else if (/^diff-./i.test(name)) {
126134
// the "diff-xxxx" format is used by the Diff Highlight plugin
127135
return ['diff', name.slice('diff-'.length)];
128-
} else {
136+
}
137+
else {
129138
return [name];
130139
}
131140
}
@@ -140,7 +149,7 @@ export default {
140149
deps.push(...mapDependency(name));
141150
}
142151

143-
deps = deps.filter((name) => !isLoaded(Prism, name));
152+
deps = deps.filter(name => !isLoaded(Prism, name));
144153
if (deps.length === 0) {
145154
// all dependencies are already loaded
146155
return;
@@ -149,10 +158,12 @@ export default {
149158
const autoloader = Prism.plugins.autoloader as Autoloader;
150159
autoloader.loadLanguages(deps).then(
151160
() => Prism.highlightElement(element),
152-
(reason) => {
153-
console.error(`Failed to load languages (${deps.join(', ')}): ${String(reason)}`);
161+
reason => {
162+
console.error(
163+
`Failed to load languages (${deps.join(', ')}): ${String(reason)}`
164+
);
154165
}
155166
);
156167
});
157-
}
168+
},
158169
} as PluginProto<'autoloader'>;

src/plugins/command-line/prism-command-line.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
.command-line-prompt > span:before {
1818
opacity: 0.7;
19-
content: ' ';
19+
content: " ";
2020
display: block;
2121
padding-right: 0.8em;
2222
}

0 commit comments

Comments
 (0)