Skip to content

Commit

Permalink
style: Apply prettier to all code (#447)
Browse files Browse the repository at this point in the history
and merge eslint configs as far as possible.

CodeQL discovered some new warnings after the formatting regading unused
variables.
I confirmed that all of them could be either fixed or be dismissed and
applied the changes as part of this PR.

Fixes #29 
Fixes #130
  • Loading branch information
karfau committed Oct 19, 2022
1 parent 4a990d3 commit 6601a11
Show file tree
Hide file tree
Showing 55 changed files with 3,381 additions and 3,873 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Expand Up @@ -7,3 +7,4 @@ indent_style = tab
indent_size = 2
end_of_line = lf
insert_final_newline = true
max_line_length = 130
18 changes: 5 additions & 13 deletions .eslintrc.yml
Expand Up @@ -3,27 +3,19 @@ env:
commonjs: true
es2020: true
node: true
extends: 'plugin:prettier/recommended'

plugins:
- es5
- anti-trojan-source
# FUTURE TBD:
# extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 11
rules:
"anti-trojan-source/no-bidi":
- error
# FUTURE TBD:
# indent:
# - error
# - tab
linebreak-style:
- error
- unix
# FUTURE TBD:
# quotes:
# - error
# - single
# semi:
# - error
# - always
strict:
- error
- global
3 changes: 2 additions & 1 deletion .prettierrc.yaml
@@ -1,3 +1,4 @@
useTabs: true
semi: false
semi: true
trailingComma: es5
singleQuote: true
34 changes: 17 additions & 17 deletions examples/nodejs/package.json
@@ -1,19 +1,19 @@
{
"name": "@xmldom/xmldom-example-nodejs",
"private": true,
"description": "Show how to use xmldom in a nodejs project",
"main": "src/index.js",
"scripts": {
"test": "node src/index.js"
},
"keywords": [
"test",
"commonjs",
"nodejs"
],
"author": "",
"license": "MIT",
"dependencies": {
"@xmldom/xmldom": "file:../.."
}
"name": "@xmldom/xmldom-example-nodejs",
"private": true,
"description": "Show how to use xmldom in a nodejs project",
"main": "src/index.js",
"scripts": {
"test": "node src/index.js"
},
"keywords": [
"test",
"commonjs",
"nodejs"
],
"author": "",
"license": "MIT",
"dependencies": {
"@xmldom/xmldom": "file:../.."
}
}
11 changes: 6 additions & 5 deletions examples/nodejs/src/index.js
@@ -1,15 +1,16 @@
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')
'use strict';
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');

const source = `<xml xmlns="a">
<child>test</child>
<child/>
</xml>`
</xml>`;

const doc = new DOMParser().parseFromString(source, 'text/xml')
const doc = new DOMParser().parseFromString(source, 'text/xml');

const serialized = new XMLSerializer().serializeToString(doc)
const serialized = new XMLSerializer().serializeToString(doc);

if (source !== serialized) {
console.error(`expected\n${source}\nbut was\n${serialized}`)
console.error(`expected\n${source}\nbut was\n${serialized}`);
process.exit(1);
}
40 changes: 20 additions & 20 deletions examples/typescript-node-es6/package.json
@@ -1,22 +1,22 @@
{
"name": "@xmldom/xmldom-example-typescript-node-es6",
"private": true,
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"tsc": "tsc",
"test": "node dist/index.js"
},
"keywords": [
"test",
"typescript"
],
"license": "MIT",
"devDependencies": {
"typescript": "*"
},
"dependencies": {
"@xmldom/xmldom": "file:../.."
}
"name": "@xmldom/xmldom-example-typescript-node-es6",
"private": true,
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"tsc": "tsc",
"test": "node dist/index.js"
},
"keywords": [
"test",
"typescript"
],
"license": "MIT",
"devDependencies": {
"typescript": "*"
},
"dependencies": {
"@xmldom/xmldom": "file:../.."
}
}
12 changes: 6 additions & 6 deletions examples/typescript-node-es6/src/index.ts
@@ -1,16 +1,16 @@
import {DOMParser, XMLSerializer} from '@xmldom/xmldom';
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';

const source = `<xml xmlns="a">
<child>test</child>
<child/>
</xml>`
</xml>`;

const doc = new DOMParser().parseFromString(source, 'text/xml')
const doc = new DOMParser().parseFromString(source, 'text/xml');

if (!doc) throw 'expected Document but was undefined'
if (!doc) throw 'expected Document but was undefined';

const serialized = new XMLSerializer().serializeToString(doc)
const serialized = new XMLSerializer().serializeToString(doc);

if (source !== serialized) {
throw `expected\n${source}\nbut was\n${serialized}`
throw `expected\n${source}\nbut was\n${serialized}`;
}
182 changes: 92 additions & 90 deletions examples/typescript-node-es6/tsconfig.json

Large diffs are not rendered by default.

56 changes: 27 additions & 29 deletions lib/conventions.js
@@ -1,4 +1,4 @@
'use strict'
'use strict';

/**
* "Shallow freezes" an object to render it immutable.
Expand All @@ -17,9 +17,9 @@
*/
function freeze(object, oc) {
if (oc === undefined) {
oc = Object
oc = Object;
}
return oc && typeof oc.freeze === 'function' ? oc.freeze(object) : object
return oc && typeof oc.freeze === 'function' ? oc.freeze(object) : object;
}

/**
Expand All @@ -37,14 +37,14 @@ function freeze(object, oc) {
*/
function assign(target, source) {
if (target === null || typeof target !== 'object') {
throw new TypeError('target is not an object')
throw new TypeError('target is not an object');
}
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
target[key] = source[key];
}
}
return target
return target;
}

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ var HTML_BOOLEAN_ATTRIBUTES = freeze({
required: true,
reversed: true,
selected: true,
})
});

/**
* Check if `name` is matching one of the HTML boolean attribute names.
Expand All @@ -100,7 +100,7 @@ var HTML_BOOLEAN_ATTRIBUTES = freeze({
* @see https://html.spec.whatwg.org/#attributes-3
*/
function isHTMLBooleanAttribute(name) {
return HTML_BOOLEAN_ATTRIBUTES.hasOwnProperty(name.toLowerCase())
return HTML_BOOLEAN_ATTRIBUTES.hasOwnProperty(name.toLowerCase());
}

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ var HTML_VOID_ELEMENTS = freeze({
source: true,
track: true,
wbr: true,
})
});

/**
* Check if `tagName` is matching one of the HTML void element names.
Expand All @@ -144,7 +144,7 @@ var HTML_VOID_ELEMENTS = freeze({
* @see https://html.spec.whatwg.org/#void-elements
*/
function isHTMLVoidElement(tagName) {
return HTML_VOID_ELEMENTS.hasOwnProperty(tagName.toLowerCase())
return HTML_VOID_ELEMENTS.hasOwnProperty(tagName.toLowerCase());
}

/**
Expand All @@ -161,7 +161,7 @@ var HTML_RAW_TEXT_ELEMENTS = freeze({
style: false,
textarea: true,
title: true,
})
});

/**
* Check if `tagName` is matching one of the HTML raw text element names.
Expand Down Expand Up @@ -227,7 +227,7 @@ var MIME_TYPE = freeze({
* @see [`DOMParser.parseFromString` @ HTML Specification](https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring)
*/
isHTML: function (value) {
return value === MIME_TYPE.HTML
return value === MIME_TYPE.HTML;
},

/**
Expand All @@ -242,9 +242,7 @@ var MIME_TYPE = freeze({
* @see https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
*/
hasDefaultHTMLNamespace: function (mimeType) {
return (
MIME_TYPE.isHTML(mimeType) || mimeType === MIME_TYPE.XML_XHTML_APPLICATION
)
return MIME_TYPE.isHTML(mimeType) || mimeType === MIME_TYPE.XML_XHTML_APPLICATION;
},

/**
Expand Down Expand Up @@ -283,7 +281,7 @@ var MIME_TYPE = freeze({
* @see https://en.wikipedia.org/wiki/Scalable_Vector_Graphics Wikipedia
*/
XML_SVG_IMAGE: 'image/svg+xml',
})
});

/**
* Namespaces that are used in this code base.
Expand All @@ -306,7 +304,7 @@ var NAMESPACE = freeze({
* @see NAMESPACE.HTML
*/
isHTML: function (uri) {
return uri === NAMESPACE.HTML
return uri === NAMESPACE.HTML;
},

/**
Expand All @@ -329,16 +327,16 @@ var NAMESPACE = freeze({
* @see https://www.w3.org/2000/xmlns/
*/
XMLNS: 'http://www.w3.org/2000/xmlns/',
})
});

exports.assign = assign
exports.freeze = freeze
exports.HTML_BOOLEAN_ATTRIBUTES = HTML_BOOLEAN_ATTRIBUTES
exports.HTML_RAW_TEXT_ELEMENTS = HTML_RAW_TEXT_ELEMENTS
exports.HTML_VOID_ELEMENTS = HTML_VOID_ELEMENTS
exports.isHTMLBooleanAttribute = isHTMLBooleanAttribute
exports.isHTMLRawTextElement = isHTMLRawTextElement
exports.isHTMLEscapableRawTextElement = isHTMLEscapableRawTextElement
exports.isHTMLVoidElement = isHTMLVoidElement
exports.MIME_TYPE = MIME_TYPE
exports.NAMESPACE = NAMESPACE
exports.assign = assign;
exports.freeze = freeze;
exports.HTML_BOOLEAN_ATTRIBUTES = HTML_BOOLEAN_ATTRIBUTES;
exports.HTML_RAW_TEXT_ELEMENTS = HTML_RAW_TEXT_ELEMENTS;
exports.HTML_VOID_ELEMENTS = HTML_VOID_ELEMENTS;
exports.isHTMLBooleanAttribute = isHTMLBooleanAttribute;
exports.isHTMLRawTextElement = isHTMLRawTextElement;
exports.isHTMLEscapableRawTextElement = isHTMLEscapableRawTextElement;
exports.isHTMLVoidElement = isHTMLVoidElement;
exports.MIME_TYPE = MIME_TYPE;
exports.NAMESPACE = NAMESPACE;

0 comments on commit 6601a11

Please sign in to comment.