-
Notifications
You must be signed in to change notification settings - Fork 0
Linters & code standards
As per recommendation by the teacher, I've decided to use (ESlint)[https://eslint.org/] as the default linter for this project. ESlint helps users finding problems in your code by analyzing javascript (and typescript) files in your project. Once an issue is found, the user is presented with several options, such as ignoring the problem or solving the issue automatically.
Using a linter is beneficial for your project as it forces you and your collaborators to follow one style guide. Having that in place, it cancels out syntax and formatting issues when you're debugging.
Getting Started with ESLint. (n.d.). Retrieved May 22, 2020, from https://eslint.org/docs/user-guide/getting-started
As for code standards, I had been going through different sets of criteria: Google's, Airbnb's, and Standard's.
Feature | Airbnb | Standard | |
---|---|---|---|
Tabs | - | 2 | - |
Semicolon | Required | Required | No |
Trailing Commas | Required | Required | No |
Template strings | Prefer | No preference | No preference |
Import Extensions | None | No preference | No preference |
Object Curly Spacing | Yes | None | Consistent |
Array Bracket Spacing | None | None | - |
Parentheses Around Arrow Function Arg | - | Required | - |
JSDocs | - | Required | - |
Console statements | - | None | None |
Underscored functions | None | Allowed | Allowed |
Space before function parentheses | None | None | Required |
As seen in the table above, it's obvious that Standard is very loose with their conventions, it leaves too much room to make mistakes or be inconsistent. With Standard out of the race, it's Airbnb vs. Google. In my testing with both conventions in my project files, I noticed that Airbnb's style uses template strings. It is not much of an issue, but it is (in my opinion) unneeded. It does allow flexibility in your code, but enforcing makes no sense. Other than that, Airbnb's convention forced object deconstruction more aggressively than Google:
* Airbnb
const { firstName } = req.body;
* Google
const firstName = req.body.firstName;
It is nice to have if it were consistent with es6 module imports (import { parts } from 'module';
), but it's not. And for those reasons, I've chosen to use Google's conventions over Airbnb's.
Uistephen. (2018, June 19). Linting ES2015+ — ESLint with StyleGuides: Google, AirBnB, Common. Retrieved from https://medium.com/@uistephen/style-guides-for-linting-ecmascript-2015-eslint-common-google-airbnb-6c25fd3dff0