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

Extend eslint-rules #985

Closed
narickmann opened this issue Dec 22, 2022 · 2 comments · Fixed by #986
Closed

Extend eslint-rules #985

narickmann opened this issue Dec 22, 2022 · 2 comments · Fixed by #986

Comments

@narickmann
Copy link
Contributor

In Studio we already use eslint-config with few rules.
To keep the code readable, nice, and consistent, I would like to add a few more rules.
I looked at the eslint rules and picked out a few that I think are useful.

Feedback and further suggestions on the rules are of course welcome.

I would like to implement these rules:

  • "arrow-spacing": "error"
    -> Enforce spacing before and after the arrow in arrow functions
  • "brace-style": "error"
    -> Enforce consistent brace style for blocks
  • "comma-spacing": ["error", { "before": false, "after": true }]
    -> Enforces consistent spacing after commas in variable declarations, array literals, object literals, function parameters, and sequences
  • "eol-last": ["error", "always"]
    -> Enforces that files end with a newline (LF)
  • "func-call-spacing": ["error", "never"]
    -> Disallows spaces between the function name and the opening parenthesis that calls it
  • "indent": ["error", 2]
    -> Enforce consistent indentation
  • "linebreak-style": ["error", "unix"]
    -> Enforce consistent linebreak style
  • "max-len": ["error", { "code": 120, "ignoreUrls": true }]
    -> Enforce a maximum line length
  • "no-multi-spaces": ["warn", { "ignoreEOLComments": true }]
    -> Disallow multiple whitespaces around logical expressions, conditional expressions, declarations, array elements, object properties, sequences and function parameters
  • "no-trailing-spaces": "error"
    -> Disallow trailing whitespace (spaces, tabs, and other Unicode whitespace characters) at the end of lines
  • "object-curly-spacing": ["error", "always"]
    -> Enforce consistent spacing inside braces of object literals, destructuring assignments, and import/export specifiers
  • "semi": ["error", "always"]
    -> Require semicolons at the end of statements
  • "space-before-function-paren": ["error", "never"]
    -> Disallow spacing before function parentheses
  • "space-infix-ops": "error"
    -> Require spacing around operators

I'm not quite sure if these rules are too much:

  • "array-bracket-spacing": ["error", "always"]
    -> Enforces consistent spacing inside array brackets
  • "arrow-parens": ["error", "as-needed"]
    -> Enforces parentheses around arrow function parameters as-needed
  • "jsx-quotes": ["error", "prefer-double"] or "jsx-quotes": ["error", "prefer-single"]
    -> Enforce the consistent use of either double or single quotes in JSX attributes
@lkiesow
Copy link
Contributor

lkiesow commented Dec 22, 2022

All suggested rules sound reasonable to me. No objections.

The only thing I would look out for is if one of the rules requires changing a lot of code. That can be annoying not only because you have to do the reformatting, but also because that means you cannot any longer easily find out why a given line was changed (last commit). Or rather, the reason will then always be formatting, which isn't helpful. If that is the case I would consider if it is worth applying that specific rule. But I don't think that will be a problem for most of these.

I like having these things checked automatically!

@narickmann
Copy link
Contributor Author

narickmann commented Dec 23, 2022

I also want to add: "block-spacing": ["error", "always"] (Enforces consistent spacing inside an open block token and the next token on the same line).

Not sure if we want "array-bracket-spacing": ["error", "always"]
Every useState declaration will look like this: const [ state, setState ] = useState() I'm not quite sure, if I like how it looks now.

narickmann added a commit to narickmann/opencast-studio that referenced this issue Dec 23, 2022
Added more eslint-rules like described in [this issue](elan-ev#985).
This resolves elan-ev#985

Haven't added `"array-bracket-spacing": ["error", "always"]` yet. Every useState declaration will look like this: `const [ state, setState ] = useState()` not quite sure, if I like how it looks.
I think I will wait for feedback for this rule.
lkiesow pushed a commit that referenced this issue Dec 23, 2022
Added more eslint-rules like described in [this issue](#985).
This resolves #985

Haven't added `"array-bracket-spacing": ["error", "always"]` yet. Every useState declaration will look like this: `const [ state, setState ] = useState()` not quite sure, if I like how it looks.
I think I will wait for feedback for this rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants