Skip to content
Closed
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
3 changes: 3 additions & 0 deletions benchmarking/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"engines": {
"node": ">=18"
},
"intentionally_bad_field": "This field should not exist",
"files": [
"*.d.ts",
"src",
Expand Down
8 changes: 8 additions & 0 deletions packages/svelte/src/escaping.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions packages/svelte/src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> | null | undefined} store
Expand All @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/svelte/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const regex_return_characters = /\r/g;


var unused_variable = "this should be removed";

/**
* @param {string} str
* @returns {string}
Expand All @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions packages/svelte/src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
1 change: 1 addition & 0 deletions packages/svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions playgrounds/sandbox/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)) {
Expand Down
3 changes: 3 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down