Open reboottime opened 1 year ago
To leverage eslint, understanding these core concepts in eslint is critical.
npm init @eslint/config
After a series of guiding steps from the above command, you will get a basic eslint configuration file .eslintrc.cjs
under your root folder.
Understand ESlint configuration core concepts
module.exports = {
parser: "@typescript-eslint/parser",
}
env
lets you configure language options specific to the JavaScript used in your project."multiline-ternary": ["error", "always"],
: force breaking ternary into multiple linespadding-line-between-statements
: supported natively by eslint"typescript-sort-keys"
: force sort typescript keys in an alphabetized. order(to be continuted...)
Though we add eslint configuration files for good intentions, sometimes , people might push code without eslint styling awareness due to eslint is not enabled on vscode.
What if we can reject a git commit if it violates our configured rules? Luckly, git provides a series of Git Hooks (opens new window):
pre-commit
pre-push
pre-merge
pre-rebase
These hooks give us some zone on committing code, let a tool to format our code automatically before commiting code.
Here, we have two tools to implement the desired feature we mentioned above.
Abstract
This note tracked why we need eslint and how to use eslint in Valina JavaScript and TypeScript projects.
Background
Why?: People may have different habits and preferences on how to format code and name a variable. While this is not necessarily a problem, team collaboration, codebase maintainability, and readability would be annoying issues when working with other people on a large project.
So here comes a question, how can I enforce a consistent style across team members?
JSLint is the first trial of the above problem. Eslint, a successor, is adopted widely by developers. After typescript adoptions, typescript-eslint project emerged to satisfy the needs of force code style on typescript projects.