Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assure valid jsdoc #319

Merged
merged 16 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

/**
* @see {@link https://eslint.org/}
* @type {import('eslint').Linter.Config}
* @see {@link https://eslint.org/}
*/
module.exports = {
root: true,
/** @see https://github.com/standard/ts-standard */
extends: 'standard-with-typescript',
extends: [
/* see https://github.com/standard/ts-standard */
'standard-with-typescript',
/* see https://github.com/gajus/eslint-plugin-jsdoc */
'plugin:jsdoc/recommended'
],
parserOptions: {
project: './tsconfig.json'
},
plugins: [
/* see https://github.com/lydell/eslint-plugin-simple-import-sort#readme */
'simple-import-sort'
],
env: {
Expand All @@ -49,16 +54,60 @@ module.exports = {
node: true,
browser: false // change, when mocha is enabled for browser
}
},
{
files: ['*.js'],
rules: {
'jsdoc/require-param-type': 'error',
'jsdoc/require-property-type': 'error',
'jsdoc/require-returns-type': 'error'
},
settings: {
jsdoc: {
/* see https://github.com/gajus/eslint-plugin-jsdoc */
mode: 'jsdoc'
}
}
}
],
rules: {
// region sort imports/exports
/** disable other sorters in favour of `simple-import-sort` **/
/* disable other sorters in favour of `simple-import-sort` */
'import/order': 0,
'sort-imports': 0,
/** @see https://github.com/lydell/eslint-plugin-simple-import-sort/ */
/* see https://github.com/lydell/eslint-plugin-simple-import-sort/ */
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error'
'simple-import-sort/exports': 'error',
// endregion sort imports/exports
// region docs
/* see https://github.com/gajus/eslint-plugin-jsdoc */
'jsdoc/no-undefined-types': 'error',
'jsdoc/check-tag-names': 0,
'jsdoc/check-types': 'error',
'jsdoc/require-hyphen-before-param-description': ['error', 'always'],
'jsdoc/require-jsdoc': 0,
'jsdoc/require-param': 0,
'jsdoc/require-param-description': 0,
'jsdoc/require-param-name': 'error',
'jsdoc/require-param-type': 0,
'jsdoc/require-property': 0,
'jsdoc/require-property-description': 0,
'jsdoc/require-property-name': 'error',
'jsdoc/require-property-type': 0,
'jsdoc/require-returns': 0,
'jsdoc/require-returns-check': 'error',
'jsdoc/require-returns-description': 0,
'jsdoc/require-returns-type': 0,
'jsdoc/require-throws': 'error',
'jsdoc/require-yields': 0,
'jsdoc/require-yields-check': 'error',
'jsdoc/sort-tags': 'warn'
// endregion docs
},
settings: {
jsdoc: {
/* see https://github.com/gajus/eslint-plugin-jsdoc */
mode: 'typescript'
}
}
}
31 changes: 31 additions & 0 deletions libs/universal-node-xml/stringifiers/helpers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
'use strict'
/*!
This file is part of CycloneDX JavaScript Library.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/

/**
* @typedef {import('../../../src/serialize/xml/types').SimpleXml.Element} Element
*/

/**
* @param {Element} element
* @return {string|string|null}
*/
module.exports.getNS = function (element) {
const ns = (element.namespace ?? element.attributes?.xmlns)?.toString() ?? ''
return ns.length > 0
? ns
: null
}

/**
* @param {string|number} space
* @return {string}
*/
module.exports.makeIndent = function (space) {
if (typeof space === 'number') {
return ' '.repeat(Math.max(0, space))
Expand Down
18 changes: 18 additions & 0 deletions libs/universal-node-xml/stringifiers/xmlbuilder2.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ module.exports = typeof create === 'function'
? stringify
: undefined

/**
* @typedef XMLBuilder - something from {import('xmlbuilder2')} that was not properly exported...
*/

/**
* @typedef {import('../../../src/serialize/xml/types').SimpleXml.Element} Element
*/

/**
* @param {Element} element
* @param {string|number} space
* @return {string}
*/
function stringify (element, { space } = {}) {
const indent = makeIndent(space)
const doc = create({ encoding: 'UTF-8' })
Expand All @@ -37,6 +50,11 @@ function stringify (element, { space } = {}) {
})
}

/**
* @param {XMLBuilder} parent
* @param {Element} element
* @param {string|null} parentNS
*/
function addEle (parent, element, parentNS = null) {
if (element.type !== 'element') { return }
const ns = getNS(element) ?? parentNS
Expand Down
Loading