From 197811cf6539a2ea6870ac2432bf2bf4f549f9a1 Mon Sep 17 00:00:00 2001 From: jdalton Date: Fri, 15 Nov 2024 16:21:30 -0500 Subject: [PATCH] feat: update prettier rules/config --- .editorconfig | 10 +++++++--- .gitattributes | 1 + .gitignore | 9 ++++++++- .prettierignore | 4 +--- .prettierrc | 7 +++++++ .prettierrc.json | 7 ------- package-lock.json | 4 ++-- src/package-url.js | 2 +- src/purl-component.js | 4 ++-- src/purl-type.js | 2 +- test/benchmark.spec.js | 2 +- test/package-url.spec.js | 20 ++++++++++---------- 12 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 .gitattributes create mode 100644 .prettierrc delete mode 100644 .prettierrc.json diff --git a/.editorconfig b/.editorconfig index 821a94a..459f3d6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,10 @@ root = true -[*.js] -indent_size = 2 -indent_style = space +[*] +charset = utf-8 end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 646ac51..6aecfcb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ .DS_Store -node_modules/ +._.DS_Store +Thumbs.db +/.env +/.nvm +/.vscode +/npm-debug.log +/yarn.lock +**/node_modules diff --git a/.prettierignore b/.prettierignore index 5a70081..ebda0f5 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,3 @@ -# Ignore artifacts: +.github/ *.json -*.xml -*.yml *.md diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8ba197e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "arrowParens": "avoid", + "semi": false, + "singleQuote": true, + "trailingComma": "none", + "proseWrap": "always" +} diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 3e119bd..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "tabWidth": 4, - "useTabs": false, - "semi": false, - "singleQuote": true, - "trailingComma": "none" -} diff --git a/package-lock.json b/package-lock.json index ff9f0c4..9d59b1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "packageurl-js", - "version": "1.2.1", + "version": "2.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "packageurl-js", - "version": "1.2.1", + "version": "2.0.1", "license": "MIT", "devDependencies": { "mocha": "^10.4.0", diff --git a/src/package-url.js b/src/package-url.js index 19726ec..ec32336 100644 --- a/src/package-url.js +++ b/src/package-url.js @@ -232,7 +232,7 @@ class PackageURL { let rawQualifiers const { searchParams } = url if (searchParams.size !== 0) { - searchParams.forEach((value) => + searchParams.forEach(value => decodePurlComponent('qualifiers', value) ) // Split the remainder once from right on '?'. diff --git a/src/purl-component.js b/src/purl-component.js index db76f15..4a03aa2 100644 --- a/src/purl-component.js +++ b/src/purl-component.js @@ -32,10 +32,10 @@ const { validateSubpath } = require('./validate') -const PurlComponentEncoder = (comp) => +const PurlComponentEncoder = comp => isNonEmptyString(comp) ? encodeURIComponent(comp) : '' -const PurlComponentStringNormalizer = (comp) => +const PurlComponentStringNormalizer = comp => typeof comp === 'string' ? comp : undefined const PurlComponentValidator = (_comp, _throws) => true diff --git a/src/purl-type.js b/src/purl-type.js index 031f585..75d7ed3 100644 --- a/src/purl-type.js +++ b/src/purl-type.js @@ -16,7 +16,7 @@ const { const { validateEmptyByType, validateRequiredByType } = require('./validate') const { PurlError } = require('./error') -const PurlTypNormalizer = (purl) => purl +const PurlTypNormalizer = purl => purl const PurlTypeValidator = (_purl, _throws) => true diff --git a/test/benchmark.spec.js b/test/benchmark.spec.js index 7654aeb..44907df 100644 --- a/test/benchmark.spec.js +++ b/test/benchmark.spec.js @@ -7,7 +7,7 @@ const { PackageURL } = require('../src/package-url') describe('PackageURL', () => { it('Benchmarking the library', () => { const iterations = 10000 - const data = TEST_FILE.filter((obj) => !obj.is_invalid) + const data = TEST_FILE.filter(obj => !obj.is_invalid) const { length: dataLength } = data const objects = [] for (let i = 0; i < iterations; i += dataLength) { diff --git a/test/package-url.spec.js b/test/package-url.spec.js index bafae8a..3db1a1d 100644 --- a/test/package-url.spec.js +++ b/test/package-url.spec.js @@ -86,7 +86,7 @@ describe('PackageURL', function () { } it('should validate required params', function () { - const testValid = (paramName) => { + const testValid = paramName => { const paramIndex = paramMap[paramName] const args = createArgs(paramName, paramName) const message = JSON.stringify(args[paramIndex]) @@ -98,7 +98,7 @@ describe('PackageURL', function () { } } - const testInvalid = (paramName) => { + const testInvalid = paramName => { const paramIndex = paramMap[paramName] ;[ createArgs(paramName, 0), @@ -109,7 +109,7 @@ describe('PackageURL', function () { createArgs(paramName, null), createArgs(paramName, undefined), createArgs(paramName, '') - ].forEach((args) => { + ].forEach(args => { const message = JSON.stringify(args[paramIndex]) try { new PackageURL(...args) @@ -120,21 +120,21 @@ describe('PackageURL', function () { }) } - ;['type', 'name'].forEach((paramName) => { + ;['type', 'name'].forEach(paramName => { testValid(paramName) testInvalid(paramName) }) }) it('should validate string params', function () { - const testValid = (paramName) => { + const testValid = paramName => { const paramIndex = paramMap[paramName] ;[ createArgs(paramName, paramName), createArgs(paramName, null), createArgs(paramName, undefined), createArgs(paramName, '') - ].forEach((args) => { + ].forEach(args => { const message = JSON.stringify(args[paramIndex]) try { new PackageURL(...args) @@ -145,7 +145,7 @@ describe('PackageURL', function () { }) } - const testInvalid = (paramName) => { + const testInvalid = paramName => { const paramIndex = paramMap[paramName] ;[ createArgs(paramName, 0), @@ -153,7 +153,7 @@ describe('PackageURL', function () { createArgs(paramName, 1), createArgs(paramName, true), createArgs(paramName, {}) - ].forEach((args) => { + ].forEach(args => { const message = JSON.stringify(args[paramIndex]) try { new PackageURL(...args) @@ -164,7 +164,7 @@ describe('PackageURL', function () { }) } - ;['namespace', 'version', 'subpath'].forEach((paramName) => { + ;['namespace', 'version', 'subpath'].forEach(paramName => { testValid(paramName) testInvalid(paramName) }) @@ -215,7 +215,7 @@ describe('PackageURL', function () { describe('toString()', function () { it('type is validated', function () { - ;['ty#pe', 'ty@pe', 'ty/pe', '1type'].forEach((type) => { + ;['ty#pe', 'ty@pe', 'ty/pe', '1type'].forEach(type => { assert.throws( () => new PackageURL(type, undefined, 'name'), /contains an illegal character|cannot start with a number/