eslint-plugin-no-em-dash
v1.0.0
Published
ESLint rule to disallow em dash characters in code
Maintainers
Readme
eslint-plugin-no-em-dash
ESLint rule to disallow em dash characters in code.
Requirements
- Node.js >= 18.18.0
- ESLint >= 8.0.0
Installation
npm install eslint-plugin-no-em-dash --save-devUsage
ESLint 9.x (Flat Config) - Recommended
In your eslint.config.js:
import noEmDash from "eslint-plugin-no-em-dash";
export default [
// Use the recommended flat config
noEmDash.configs["flat/recommended"],
// Or configure manually
{
plugins: {
"no-em-dash": noEmDash
},
rules: {
"no-em-dash/no-em-dash": "error"
}
}
];ESLint 8.x (Legacy Config)
In your .eslintrc.js or .eslintrc.json:
{
"plugins": ["no-em-dash"],
"rules": {
"no-em-dash/no-em-dash": "error"
}
}Or use the recommended config:
{
"extends": ["plugin:no-em-dash/recommended"]
}Rules
no-em-dash
Disallows em dash characters (U+2014) in string literals and template literals.
Why?
- Em dashes are often inserted by auto-correct in editors and word processors
- They can cause issues when code is shared across different environments
- Regular hyphens are easier to type and more universally supported
- Prevents copy-paste issues from external documents
Examples of incorrect code:
const message = "Hello - world"; // em dash
const template = `Status - OK`; // em dashExamples of correct code:
const message = "Hello - world"; // regular hyphen
const template = `Status - OK`; // regular hyphenLicense
MIT
