diff --git a/source/.eslintrc.yml b/source/.eslintrc.yml index 098d8e43..e3db540c 100644 --- a/source/.eslintrc.yml +++ b/source/.eslintrc.yml @@ -81,7 +81,6 @@ rules: no-multiple-empty-lines: error no-multi-str: error no-multi-assign: error - no-inline-comments: error yoda: error max-classes-per-file: [error, 1] grouped-accessor-pairs: error @@ -116,9 +115,6 @@ rules: quotes: [error, double, {avoidEscape: true}] template-curly-spacing: error - # Coding style (comments rules) - line-comment-position: error - # Coding style (spacing rules) block-spacing: [error, always] comma-spacing: error diff --git a/source/app/metrics/metadata.mjs b/source/app/metrics/metadata.mjs index 583831c1..0e612f16 100644 --- a/source/app/metrics/metadata.mjs +++ b/source/app/metrics/metadata.mjs @@ -233,9 +233,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) { comment: "", descriptor: yaml.dump({ [key]: Object.fromEntries( - Object.entries(value).filter(([key]) => ["description", "default", "required"].includes(key)).map(([k, v]) => - k === "description" ? [k, v.split("\n")[0]] : k === "default" ? [k, ((/^\$\{\{[\s\S]+\}\}$/.test(v)) || (["config_presets", "config_timezone", "use_prebuilt_image"].includes(key))) ? v : ""] : [k, v] - ), + Object.entries(value).filter(([key]) => ["description", "default", "required"].includes(key)).map(([k, v]) => k === "description" ? [k, v.split("\n")[0]] : k === "default" ? [k, ((/^\$\{\{[\s\S]+\}\}$/.test(v)) || (["config_presets", "config_timezone", "use_prebuilt_image"].includes(key))) ? v : ""] : [k, v]), ), }, {quotingType: '"', noCompatMode: true}), }, diff --git a/source/app/web/statics/app.js b/source/app/web/statics/app.js index f44ad097..3b328cc0 100644 --- a/source/app/web/statics/app.js +++ b/source/app/web/statics/app.js @@ -238,13 +238,9 @@ ` template: ${this.templates.selected}`, ` base: ${Object.entries(this.plugins.enabled.base).filter(([key, value]) => value).map(([key]) => key).join(", ") || '""'}`, ...[ - ...Object.entries(this.plugins.options).filter(([key, value]) => (key in metadata.base.web) && (value !== metadata.base.web[key]?.defaulted)).map(([key, value]) => - ` ${key.replace(/[.]/g, "_")}: ${typeof value === "boolean" ? {true: "yes", false: "no"}[value] : value}` - ), + ...Object.entries(this.plugins.options).filter(([key, value]) => (key in metadata.base.web) && (value !== metadata.base.web[key]?.defaulted)).map(([key, value]) => ` ${key.replace(/[.]/g, "_")}: ${typeof value === "boolean" ? {true: "yes", false: "no"}[value] : value}`), ...Object.entries(this.plugins.enabled).filter(([key, value]) => (key !== "base") && (value)).map(([key]) => ` plugin_${key}: yes`), - ...Object.entries(this.plugins.options).filter(([key, value]) => value).filter(([key, value]) => this.plugins.enabled[key.split(".")[0]]).map(([key, value]) => - ` plugin_${key.replace(/[.]/g, "_")}: ${typeof value === "boolean" ? {true: "yes", false: "no"}[value] : value}` - ), + ...Object.entries(this.plugins.options).filter(([key, value]) => value).filter(([key, value]) => this.plugins.enabled[key.split(".")[0]]).map(([key, value]) => ` plugin_${key.replace(/[.]/g, "_")}: ${typeof value === "boolean" ? {true: "yes", false: "no"}[value] : value}`), ...Object.entries(this.config).filter(([key, value]) => (value) && (value !== metadata.core.web[key]?.defaulted)).map(([key, value]) => ` config_${key.replace(/[.]/g, "_")}: ${typeof value === "boolean" ? {true: "yes", false: "no"}[value] : value}`), ].sort(), ].join("\n") diff --git a/source/app/web/statics/app.placeholder.js b/source/app/web/statics/app.placeholder.js index b7fe65f6..38ee7ff4 100644 --- a/source/app/web/statics/app.placeholder.js +++ b/source/app/web/statics/app.placeholder.js @@ -402,8 +402,7 @@ status: "modified", additions: faker.datatype.number(50), deletions: faker.datatype.number(50), - patch: - `@@ -0,0 +1,5 @@
//Imports
+ import app from "./src/app.mjs"
- import app from "./src/app.js"
//Start app
await app()
\\ No newline at end of file`, + patch: `@@ -0,0 +1,5 @@
//Imports
+ import app from "./src/app.mjs"
- import app from "./src/app.js"
//Start app
await app()
\\ No newline at end of file`, repo: `${faker.random.word()}/${faker.random.word()}`, }, }, diff --git a/source/plugins/languages/index.mjs b/source/plugins/languages/index.mjs index 60677377..366b98b4 100644 --- a/source/plugins/languages/index.mjs +++ b/source/plugins/languages/index.mjs @@ -128,9 +128,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled //Compute languages stats for (const {section, stats = {}, lines = {}, missed = {bytes: 0}, total = 0} of [{section: "favorites", stats: languages.stats, lines: languages.lines, total: languages.total, missed: languages.missed}, {section: "recent", ...languages["stats.recent"]}]) { console.debug(`metrics/compute/${login}/plugins > languages > computing stats ${section}`) - languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size: value, color: languages.colors[name], x: 0})).filter(({value}) => - value / total > threshold - ) + languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size: value, color: languages.colors[name], x: 0})).filter(({value}) => value / total > threshold) if (other) { let value = indepth ? missed.bytes : Object.entries(stats).filter(([name]) => !Object.values(languages[section]).map(({name}) => name).includes(name)).reduce((a, [_, b]) => a + b, 0) if (value) { diff --git a/source/plugins/lines/index.mjs b/source/plugins/lines/index.mjs index e7db0200..e68d2c53 100644 --- a/source/plugins/lines/index.mjs +++ b/source/plugins/lines/index.mjs @@ -23,9 +23,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled //Get contributors stats from repositories console.debug(`metrics/compute/${login}/plugins > lines > querying api`) const lines = {added: 0, deleted: 0, changed: 0} - const response = [...await Promise.allSettled(repositories.map(({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : rest.repos.getContributorsStats({owner, repo})))].filter(({status}) => - status === "fulfilled" - ).map(({value}) => value) + const response = [...await Promise.allSettled(repositories.map(({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : rest.repos.getContributorsStats({owner, repo})))].filter(({status}) => status === "fulfilled").map(({value}) => value) //Compute changed lines console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`) diff --git a/source/plugins/notable/index.mjs b/source/plugins/notable/index.mjs index ba3d4db4..6878cd0a 100644 --- a/source/plugins/notable/index.mjs +++ b/source/plugins/notable/index.mjs @@ -29,9 +29,7 @@ export default async function({login, q, imports, rest, graphql, data, account, } //Set contributions - contributions = (await Promise.all(contributions.map(async ({handle, stars, issues, pulls, avatarUrl, organization}) => ({name: handle.split("/").shift(), handle, stars, issues, pulls, avatar: await imports.imgb64(avatarUrl), organization})))).sort((a, b) => - a.name.localeCompare(b.name) - ) + contributions = (await Promise.all(contributions.map(async ({handle, stars, issues, pulls, avatarUrl, organization}) => ({name: handle.split("/").shift(), handle, stars, issues, pulls, avatar: await imports.imgb64(avatarUrl), organization})))).sort((a, b) => a.name.localeCompare(b.name)) console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`) //Extras features diff --git a/source/plugins/traffic/index.mjs b/source/plugins/traffic/index.mjs index f353911f..120762d0 100644 --- a/source/plugins/traffic/index.mjs +++ b/source/plugins/traffic/index.mjs @@ -16,9 +16,7 @@ export default async function({login, imports, data, rest, q, account}, {enabled //Get views stats from repositories console.debug(`metrics/compute/${login}/plugins > traffic > querying api`) const views = {count: 0, uniques: 0} - const response = [...await Promise.allSettled(repositories.map(({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : rest.repos.getViews({owner, repo})))].filter(({status}) => - status === "fulfilled" - ).map(({value}) => value) + const response = [...await Promise.allSettled(repositories.map(({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : rest.repos.getViews({owner, repo})))].filter(({status}) => status === "fulfilled").map(({value}) => value) //Compute views console.debug(`metrics/compute/${login}/plugins > traffic > computing stats`) diff --git a/tests/ci.test.js b/tests/ci.test.js index ae6d5eb8..a41ae2af 100644 --- a/tests/ci.test.js +++ b/tests/ci.test.js @@ -44,6 +44,5 @@ describe("Check files editions (checkout your files if needed)", () => { //Templates editions describe("Check templates editions", () => { - test("Use community templates instead (see https://github.com/lowlighter/metrics/tree/master/source/templates/community)", async () => - void expect((await diff()).filter(edited => /^sources[/]templates[/]/.test(edited) && /^source[/]templates[/](?:classic|terminal|markdown|repository|community)[/][\s\S]*$/.test(edited)).length).toBe(0)) + test("Use community templates instead (see https://github.com/lowlighter/metrics/tree/master/source/templates/community)", async () => void expect((await diff()).filter(edited => /^sources[/]templates[/]/.test(edited) && /^source[/]templates[/](?:classic|terminal|markdown|repository|community)[/][\s\S]*$/.test(edited)).length).toBe(0)) })