no-class-assign
Disallow assigning to the name of a class
error by default
You can assign to a class declaration's name like a let variable. After that the class is gone, and every new Logger() and instanceof Logger in the file works with the new value. That's almost always a mistake.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure#
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-class-assign" = "off" # or "warn"Examples#
example.js1 problem
class Logger {}
LoggerLogger is a class. = createLogger();example.jsNo problems
class Logger {}
const logger = createLogger();A variable that holds a class expression is an ordinary variable:
example.jsNo problems
let Store = class {};
Store = class extends Store {};