The drop-em-dash-eslint-rule plugin enforces the use of plain hyphens in your code by automatically replacing em dashes. This helps maintain consistency in codebases, making them clearer and easier to read, while preventing AI-generated text pitfalls. Ideal for teams aiming for readability and uniformity.
The eslint-plugin-drop-em-dash project serves as an essential tool for developers looking to maintain clean and consistent codebases by disallowing the use of em dashes (Unicode character U+2014) and automatically fixing them to hyphens (U+002D). This initiative addresses the common issue of unwanted em dashes creeping into source codes from various sources, such as AI-generated text and word processors that automatically convert characters, potentially disrupting the readability and consistency of code.
The presence of em dashes in code can lead to several drawbacks, including:
grep may not recognize em dashes, complicating searches and refactoring.To integrate the plugin into an ESLint setup, include it in your configuration:
import dropEmDash from 'eslint-plugin-drop-em-dash';
export default [...dropEmDash.configs['flat/recommended']];
You can also use the plugin with types like .eslintrc:
{
"extends": ["plugin:drop-em-dash/recommended"]
}
Once the plugin is set up, running eslint . --fix converts any instance of an em dash in the code. For example:
const title = 'Pricing - overview'; // best plan - for teams
This will be corrected to:
const title = 'Pricing - overview'; // best plan - for teams
For those using other package managers:
pnpm add -D eslint eslint-plugin-drop-em-dash
yarn add -D eslint eslint-plugin-drop-em-dash
Comprehensive documentation can be found at: Full Docs
For testing and contributions, refer to the project's testing suite and contribution guidelines.
This ESLint plugin stands as a simple yet effective solution for ensuring consistent use of ASCII characters in the code, contributing significantly to improved code quality and maintainability.
No comments yet.
Sign in to be the first to comment.