Skip to content

VBC-904: magic-string

warning

Category: clean-code
Analysis: Regex (line by line)
File types: .js, .ts, .tsx, .astro
Scope: source code only, ignoring anything inside strings and comments
Tags: clean-code

What it reports

Magic string literal passed to function at line {line}. Use a named constant instead.

Flagged

js
configure("some long option value");

Not flagged

js
throw new Error('failed to reach the database');
js
console.log('worker pool started');
js
describe('the retry scheduler', run);

Pattern

regex
(?<![.\w$])(?!(?:Error|TypeError|RangeError|SyntaxError|EvalError|URIError|log|info|warn|error|debug|trace|assert|describe|it|test|expect|require|import|t|_|gettext|translate|print)\s*\()[a-zA-Z_$][\w$]*\(\s*['\"][a-zA-Z0-9_\s]{10,}['\"]\s*\)

Released under the MIT License.