Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -19,7 +19,7 @@ const tags = [
|
||||
'properties',
|
||||
'returns',
|
||||
'see',
|
||||
'summary'
|
||||
'summary',
|
||||
];
|
||||
|
||||
const hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
@@ -27,32 +27,32 @@ const hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
const markedRenderer = new marked.Renderer();
|
||||
|
||||
// Allow prettyprint to work on inline code samples
|
||||
markedRenderer.code = function(code, language) {
|
||||
markedRenderer.code = function (code, language) {
|
||||
const langClass = language ? ' lang-' + language : '';
|
||||
|
||||
return format('<pre class="prettyprint source%s"><code>%s</code></pre>',
|
||||
langClass, escapeCode(code));
|
||||
return format(
|
||||
'<pre class="prettyprint source%s"><code>%s</code></pre>',
|
||||
langClass,
|
||||
escapeCode(code)
|
||||
);
|
||||
};
|
||||
|
||||
function escapeCode(source) {
|
||||
return source.replace(/</g, '<')
|
||||
return source
|
||||
.replace(/</g, '<')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function escapeUnderscoresAndTildes(source) {
|
||||
return source.replace(/\{@[^}\r\n]+\}/g, function(wholeMatch) {
|
||||
return wholeMatch
|
||||
.replace(/(^|[^\\])_/g, '$1\\_')
|
||||
.replace('~', '˜');
|
||||
return source.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
|
||||
return wholeMatch.replace(/(^|[^\\])_/g, '$1\\_').replace('~', '˜');
|
||||
});
|
||||
}
|
||||
|
||||
function unencodeQuotesAndTildes(source) {
|
||||
return source.replace(/\{@[^}\r\n]+\}/g, function(wholeMatch) {
|
||||
return wholeMatch
|
||||
.replace(/"/g, '"')
|
||||
.replace(/˜/g, '~');
|
||||
return source.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
|
||||
return wholeMatch.replace(/"/g, '"').replace(/˜/g, '~');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ function parse(source) {
|
||||
|
||||
result = marked(source, {renderer: markedRenderer})
|
||||
.replace(/\s+$/, '')
|
||||
.replace(/'/g, '\'');
|
||||
.replace(/'/g, "'");
|
||||
|
||||
result = unencodeQuotesAndTildes(result);
|
||||
|
||||
@@ -82,15 +82,18 @@ function shouldProcessString(tagName, text) {
|
||||
}
|
||||
|
||||
function process(doclet) {
|
||||
tags.forEach(function(tag) {
|
||||
tags.forEach(function (tag) {
|
||||
if (!hasOwnProp.call(doclet, tag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof doclet[tag] === 'string' && shouldProcessString(tag, doclet[tag])) {
|
||||
if (
|
||||
typeof doclet[tag] === 'string' &&
|
||||
shouldProcessString(tag, doclet[tag])
|
||||
) {
|
||||
doclet[tag] = parse(doclet[tag]);
|
||||
} else if (Array.isArray(doclet[tag])) {
|
||||
doclet[tag].forEach(function(value, index, original) {
|
||||
doclet[tag].forEach(function (value, index, original) {
|
||||
const inner = {};
|
||||
|
||||
inner[tag] = value;
|
||||
@@ -103,9 +106,8 @@ function process(doclet) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
exports.handlers = {
|
||||
newDoclet: function(e) {
|
||||
newDoclet: function (e) {
|
||||
process(e.doclet);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user