No two developers write code the same way. Indeed, in a large team of developers, everyone codes with their own style preferences.
What are code style guides, and why do you need them
A code style guide is a set of rules, standards, or best practices that outline how your team should write, format, and organize the source code. In an ideal world, your team’s source code should look like it was written by a single person, even if hundreds of developers collaborated on it.
A team following the same style guide has superpowers. Being consistent with a style guide makes your code easier to read, debug, and maintain. It is also smoother to add new features or update legacy code, and new developers have an easier integration with the team.
What’s included in a code style guide?
- Naming and declaration rules for constants, variables, and functions;
- Rules for the use of white spaces, indentation, vertical alignment, and comments;
- Folder naming, asset naming, source file structures, and folder hierarchy;
- Best programming practices and principles, focusing on conventions and coding standards.
What are the advantages of code style guides?
- Quick readability and understanding of any codebase through familiar formats;
- Streamlined code creation and maintenance, with higher code quality;
- Straightforward scaling and implementation of automation; and
- Easier to cope with change, like product ownership transfer, onboarding new people, or code handoffs.
One way of making sure you and your team use the Google style guide is by using an automated code review tool that runs analysis on your commits and PRs. We’ll show you how to create these rules in Codacy so you can have the same standards as Google.
Set up ESLint rules in Codacy
Once you have your ESLint configuration file in your repository root, Codacy will apply the rules defined in the file to your entire repo.
Set up JSHint rules in Codacy
- Enforce camel case
- Enforce curly braces
- Enforce parentheses in function calls
- Enforce quotation marks
- Excessive line length (you should set the column limit to 80)
Set up PMD rules in Codacy
- Avoid With Statement
- Consistent Return
- For Loops Must Use Braces
- If ELse Stmts Must Use Braces
- If Stmts Must Use Braces
- Unnecessary Block
- While Loops Must Use Braces