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:
@@ -2,19 +2,18 @@
|
||||
* Define an @api tag
|
||||
* @param {Object} dictionary The tag dictionary.
|
||||
*/
|
||||
exports.defineTags = function(dictionary) {
|
||||
exports.defineTags = function (dictionary) {
|
||||
dictionary.defineTag('api', {
|
||||
mustNotHaveValue: true,
|
||||
canHaveType: false,
|
||||
canHaveName: false,
|
||||
onTagged: function(doclet, tag) {
|
||||
onTagged: function (doclet, tag) {
|
||||
includeTypes(doclet);
|
||||
doclet.stability = 'stable';
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Based on @api annotations, and assuming that items with no @api annotation
|
||||
* should not be documented, this plugin removes undocumented symbols
|
||||
@@ -56,7 +55,7 @@ function includeAugments(doclet) {
|
||||
if (!doclet.fires) {
|
||||
doclet.fires = [];
|
||||
}
|
||||
cls.fires.forEach(function(f) {
|
||||
cls.fires.forEach(function (f) {
|
||||
if (doclet.fires.indexOf(f) == -1) {
|
||||
doclet.fires.push(f);
|
||||
}
|
||||
@@ -66,7 +65,7 @@ function includeAugments(doclet) {
|
||||
if (!doclet.observables) {
|
||||
doclet.observables = [];
|
||||
}
|
||||
cls.observables.forEach(function(f) {
|
||||
cls.observables.forEach(function (f) {
|
||||
if (doclet.observables.indexOf(f) == -1) {
|
||||
doclet.observables.push(f);
|
||||
}
|
||||
@@ -79,7 +78,7 @@ function includeAugments(doclet) {
|
||||
}
|
||||
|
||||
function extractTypes(item) {
|
||||
item.type.names.forEach(function(type) {
|
||||
item.type.names.forEach(function (type) {
|
||||
const match = type.match(/^(.*<)?([^>]*)>?$/);
|
||||
if (match) {
|
||||
modules[match[2]] = true;
|
||||
@@ -109,31 +108,35 @@ const moduleRoot = path.join(process.cwd(), 'src');
|
||||
|
||||
// Tag default exported Identifiers because their name should be the same as the module name.
|
||||
exports.astNodeVisitor = {
|
||||
visitNode: function(node, e, parser, currentSourceName) {
|
||||
visitNode: function (node, e, parser, currentSourceName) {
|
||||
if (node.parent && node.parent.type === 'ExportDefaultDeclaration') {
|
||||
const modulePath = path.relative(moduleRoot, currentSourceName).replace(/\.js$/, '');
|
||||
const exportName = 'module:' + modulePath.replace(/\\/g, '/') + (node.name ? '~' + node.name : '');
|
||||
const modulePath = path
|
||||
.relative(moduleRoot, currentSourceName)
|
||||
.replace(/\.js$/, '');
|
||||
const exportName =
|
||||
'module:' +
|
||||
modulePath.replace(/\\/g, '/') +
|
||||
(node.name ? '~' + node.name : '');
|
||||
defaultExports[exportName] = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function sortOtherMembers(doclet) {
|
||||
if (doclet.fires) {
|
||||
doclet.fires.sort(function(a, b) {
|
||||
doclet.fires.sort(function (a, b) {
|
||||
return a.split(/#?event:/)[1] < b.split(/#?event:/)[1] ? -1 : 1;
|
||||
});
|
||||
}
|
||||
if (doclet.observables) {
|
||||
doclet.observables.sort(function(a, b) {
|
||||
doclet.observables.sort(function (a, b) {
|
||||
return a.name < b.name ? -1 : 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.handlers = {
|
||||
|
||||
newDoclet: function(e) {
|
||||
newDoclet: function (e) {
|
||||
const doclet = e.doclet;
|
||||
if (doclet.stability) {
|
||||
modules[doclet.longname.split(/[~\.]/).shift()] = true;
|
||||
@@ -152,7 +155,7 @@ exports.handlers = {
|
||||
}
|
||||
},
|
||||
|
||||
parseComplete: function(e) {
|
||||
parseComplete: function (e) {
|
||||
const doclets = e.doclets;
|
||||
const byLongname = doclets.index.longname;
|
||||
for (let i = doclets.length - 1; i >= 0; --i) {
|
||||
@@ -183,9 +186,12 @@ exports.handlers = {
|
||||
// Remove all other undocumented symbols
|
||||
doclet.undocumented = true;
|
||||
}
|
||||
if (doclet.memberof && byLongname[doclet.memberof] &&
|
||||
byLongname[doclet.memberof][0].isEnum &&
|
||||
!byLongname[doclet.memberof][0].properties.some(p => p.stability)) {
|
||||
if (
|
||||
doclet.memberof &&
|
||||
byLongname[doclet.memberof] &&
|
||||
byLongname[doclet.memberof][0].isEnum &&
|
||||
!byLongname[doclet.memberof][0].properties.some((p) => p.stability)
|
||||
) {
|
||||
byLongname[doclet.memberof][0].undocumented = true;
|
||||
}
|
||||
}
|
||||
@@ -194,10 +200,9 @@ exports.handlers = {
|
||||
processingComplete(e) {
|
||||
const byLongname = e.doclets.index.longname;
|
||||
for (const name in defaultExports) {
|
||||
byLongname[name].forEach(function(doclet) {
|
||||
byLongname[name].forEach(function (doclet) {
|
||||
doclet.isDefaultExport = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const events = {};
|
||||
|
||||
exports.handlers = {
|
||||
|
||||
newDoclet: function(e) {
|
||||
newDoclet: function (e) {
|
||||
const doclet = e.doclet;
|
||||
if (doclet.kind !== 'event') {
|
||||
return;
|
||||
@@ -15,7 +14,7 @@ exports.handlers = {
|
||||
events[cls].push(doclet.longname);
|
||||
},
|
||||
|
||||
parseComplete: function(e) {
|
||||
parseComplete: function (e) {
|
||||
const doclets = e.doclets;
|
||||
for (let i = 0, ii = doclets.length - 1; i < ii; ++i) {
|
||||
const doclet = doclets[i];
|
||||
@@ -34,6 +33,5 @@ exports.handlers = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
const properties = {};
|
||||
|
||||
exports.handlers = {
|
||||
|
||||
/**
|
||||
* Collects all typedefs, keyed by longname
|
||||
* @param {Object} e Event object.
|
||||
*/
|
||||
newDoclet: function(e) {
|
||||
newDoclet: function (e) {
|
||||
if (e.doclet.kind == 'typedef' && e.doclet.properties) {
|
||||
properties[e.doclet.longname] = e.doclet.properties;
|
||||
}
|
||||
@@ -22,7 +21,7 @@ exports.handlers = {
|
||||
* collected typedefs.
|
||||
* @param {Object} e Event object.
|
||||
*/
|
||||
parseComplete: function(e) {
|
||||
parseComplete: function (e) {
|
||||
const doclets = e.doclets;
|
||||
for (let i = 0, ii = doclets.length; i < ii; ++i) {
|
||||
const doclet = doclets[i];
|
||||
@@ -34,16 +33,18 @@ exports.handlers = {
|
||||
const type = param.type.names[0];
|
||||
if (type in properties) {
|
||||
param.type.names[0] = type;
|
||||
params.push.apply(params, properties[type].map(p => {
|
||||
const property = Object.assign({}, p);
|
||||
property.name = `${param.name}.${property.name}`;
|
||||
return property;
|
||||
}));
|
||||
params.push.apply(
|
||||
params,
|
||||
properties[type].map((p) => {
|
||||
const property = Object.assign({}, p);
|
||||
property.name = `${param.name}.${property.name}`;
|
||||
return property;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,15 +2,14 @@ const classes = {};
|
||||
const observables = {};
|
||||
|
||||
exports.handlers = {
|
||||
|
||||
newDoclet: function(e) {
|
||||
newDoclet: function (e) {
|
||||
const doclet = e.doclet;
|
||||
if (doclet.kind == 'class' && !(doclet.longname in classes)) {
|
||||
classes[doclet.longname] = doclet;
|
||||
}
|
||||
},
|
||||
|
||||
parseComplete: function(e) {
|
||||
parseComplete: function (e) {
|
||||
const doclets = e.doclets;
|
||||
let cls, doclet, event, i, ii, observable;
|
||||
for (i = 0, ii = doclets.length - 1; i < ii; ++i) {
|
||||
@@ -26,8 +25,8 @@ exports.handlers = {
|
||||
}
|
||||
observable = observables[key];
|
||||
observable.name = name;
|
||||
observable.readonly = typeof observable.readonly == 'boolean' ?
|
||||
observable.readonly : true;
|
||||
observable.readonly =
|
||||
typeof observable.readonly == 'boolean' ? observable.readonly : true;
|
||||
if (doclet.name.indexOf('get') === 0) {
|
||||
observable.type = doclet.returns[0].type;
|
||||
observable.description = doclet.returns[0].description;
|
||||
@@ -53,17 +52,16 @@ exports.handlers = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
exports.defineTags = function(dictionary) {
|
||||
exports.defineTags = function (dictionary) {
|
||||
dictionary.defineTag('observable', {
|
||||
mustNotHaveValue: true,
|
||||
canHaveType: false,
|
||||
canHaveName: false,
|
||||
onTagged: function(doclet, tag) {
|
||||
onTagged: function (doclet, tag) {
|
||||
doclet.observable = '';
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user