Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a linter config to the repository #1729

Closed
laurent22 opened this issue Jul 13, 2019 · 1 comment
Closed

Add a linter config to the repository #1729

laurent22 opened this issue Jul 13, 2019 · 1 comment
Labels
enhancement Feature requests and code enhancements

Comments

@laurent22
Copy link
Owner

laurent22 commented Jul 13, 2019

The goal is to create an eslint file that roughly matches the existing code base conventions.

It's ok to loosen the rules to allow the codebase to pass with as few changes as possible. Or we can make these tricky rules simply emit warnings for now. If any of these rules cannot be applied to the current code base without major changes or refactoring, we'll remove it for now.

Rules

General

  • Use tabs
  • No max line length for now
  • All lines must end with ";" except on JSX where they are optional (not sure if can be done)
  • Spacing between parenthesis should be as in the code example below
  • Variables should be either "const" (prefered) or "let" if it has to mutate. No "var".
  • If statements can be on one line
  • If an if statement is on more than one line, the line(s) below must be wrapped in {}

Classes and modules

  • Exported modules must have the same name as the filename. eg. "MyComponent.jsx" would export a component named "MyComponent"
  • If it can be done: Private class variables end with trailing underscore
  • Files must end with a trailing new line (mostly because most editors add one)

Case

  • Function names camelCase, but underscores are allowed so that instanceName_eventName() is possible
  • Local variables camelCase
  • Component names as PascalCase

Strings

  • Strings must not be split over several lines (to make them more easily searchable), except in ES6 string templates
  • Strings must be wrapped in single quotes.

React

  • No anonymous functions in React event handlers
  • All React components should be PureComponent
  • Only strict equality or inequality is allowed

Example code

This is an example of code that is considered as valid:

class MyClass {

    constructor() {
        super();
    }
    
    render() {
        return <div>Hello</div>;
    }
    
}

function doSomething(one, two) {
	
}

if (something === '1') {
	doSomething(123, 456);
}

if (!something) doSomethingElse();

Implementation

Use eslint for the linter config. Use a pre-commit hook with husky to format the code before commit.

@tessus tessus added the enhancement Feature requests and code enhancements label Jul 22, 2019
@laurent22
Copy link
Owner Author

@lock lock bot locked and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Feature requests and code enhancements
Projects
None yet
Development

No branches or pull requests

2 participants