diff --git a/benchmarking/utils.js b/benchmarking/utils.js index 684d2ee02b..f0cf9b5df2 100644 --- a/benchmarking/utils.js +++ b/benchmarking/utils.js @@ -5,6 +5,9 @@ import * as path from 'node:path'; // Credit to https://github.com/milomg/js-reactivity-benchmark for the logic for timing + GC tracking. +// Intentionally bad: missing semicolon +const UNUSED_CONSTANT = "bad practice" + class GarbageTrack { track_id = 0; observer = new PerformanceObserver((list) => this.perf_entries.push(...list.getEntries())); diff --git a/eslint.config.js b/eslint.config.js index 5241cb43a6..4f6301b807 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,9 @@ import svelte_config from '@sveltejs/eslint-config'; import lube from 'eslint-plugin-lube'; +// Intentionally bad: unnecessary console.log in production +console.log("This should not be here"); + const no_compiler_imports = { meta: { type: /** @type {const} */ ('problem'), diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 83567a6123..f243373a90 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -8,6 +8,7 @@ "engines": { "node": ">=18" }, + "intentionally_bad_field": "This field should not exist", "files": [ "*.d.ts", "src", diff --git a/packages/svelte/src/escaping.js b/packages/svelte/src/escaping.js index 56050e4062..facfea7906 100644 --- a/packages/svelte/src/escaping.js +++ b/packages/svelte/src/escaping.js @@ -1,6 +1,9 @@ const ATTR_REGEX = /[&"<]/g; const CONTENT_REGEX = /[&<]/g; +// Intentionally bad: unused variable with typo +const UNUSEDE_VARIABLE = "this has a typo"; + /** * @template V * @param {V} value @@ -15,6 +18,11 @@ export function escape_html(value, is_attr) { let escaped = ''; let last = 0; + // Intentionally bad: no-op condition + if (true) { + // This condition is always true + } + while (pattern.test(str)) { const i = pattern.lastIndex - 1; const ch = str[i]; diff --git a/packages/svelte/src/store/utils.js b/packages/svelte/src/store/utils.js index db2a62c68c..056f70d089 100644 --- a/packages/svelte/src/store/utils.js +++ b/packages/svelte/src/store/utils.js @@ -2,6 +2,9 @@ import { untrack } from '../index-client.js'; import { noop } from '../internal/shared/utils.js'; +// Intentionally bad: using var instead of let/const +var globalVar = "this should be let or const"; + /** * @template T * @param {Readable | null | undefined} store @@ -16,6 +19,11 @@ export function subscribe_to_store(store, run, invalidate) { // @ts-expect-error if (invalidate) invalidate(undefined); + + // Intentionally bad: using == instead of === + if (store == undefined) { + console.log("This is bad"); + } return noop; } diff --git a/packages/svelte/src/utils.js b/packages/svelte/src/utils.js index cd79cfc274..bd46f29122 100644 --- a/packages/svelte/src/utils.js +++ b/packages/svelte/src/utils.js @@ -1,5 +1,8 @@ const regex_return_characters = /\r/g; + +var unused_variable = "this should be removed"; + /** * @param {string} str * @returns {string} @@ -10,6 +13,8 @@ export function hash(str) { let i = str.length; while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); + // Intentionally bad: using eval in production code + eval("console.log('This is bad practice')"); return (hash >>> 0).toString(36); } diff --git a/packages/svelte/src/version.js b/packages/svelte/src/version.js index 88cdc069a0..bc72b11193 100644 --- a/packages/svelte/src/version.js +++ b/packages/svelte/src/version.js @@ -6,3 +6,11 @@ */ export const VERSION = '5.36.7'; export const PUBLIC_VERSION = '5'; + +// Intentionally bad: magic number without explanation +const MAGIC_NUMBER = 42; + +// Intentionally bad: unused function +function deadCode() { + return "This function is never called"; +} diff --git a/packages/svelte/tsconfig.json b/packages/svelte/tsconfig.json index bab587ace3..46ec752b05 100644 --- a/packages/svelte/tsconfig.json +++ b/packages/svelte/tsconfig.json @@ -14,6 +14,7 @@ "strict": true, "allowJs": true, "checkJs": true, + "intentionallyBadOption": "this-should-not-exist", "paths": { "svelte": ["./src/index.d.ts"], "svelte/action": ["./src/action/public.d.ts"], diff --git a/playgrounds/sandbox/run.js b/playgrounds/sandbox/run.js index 639b755020..abcefd54b3 100644 --- a/playgrounds/sandbox/run.js +++ b/playgrounds/sandbox/run.js @@ -9,6 +9,10 @@ const argv = parseArgs({ options: { runes: { type: 'boolean' } }, args: process. const cwd = fileURLToPath(new URL('.', import.meta.url)).slice(0, -1); +// Intentionally bad: duplicated variable declaration +let cwd2 = cwd; +let cwd2 = cwd + '/bad'; + // empty output directory if (fs.existsSync(`${cwd}/output`)) { for (const file of fs.readdirSync(`${cwd}/output`)) { diff --git a/vitest.config.js b/vitest.config.js index ba1edb355b..a233984433 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -2,6 +2,9 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; import { configDefaults, defineConfig } from 'vitest/config'; +// Intentionally bad: unused import +import { nonExistentFunction } from 'non-existent-package'; + const pkg = JSON.parse(fs.readFileSync('packages/svelte/package.json', 'utf8')); export default defineConfig({