Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Add ESLint to Project#14

Merged
acjh merged 2 commits into
MarkBind:masterfrom
nicholaschuayunzhi:eslint
Jan 21, 2018
Merged

Add ESLint to Project#14
acjh merged 2 commits into
MarkBind:masterfrom
nicholaschuayunzhi:eslint

Conversation

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor

Adds ESLint and its lodash plugin as a dev dependency. --fix command not executed yet. The eslintrc file was taken from https://github.com/MarkBind/markbind/blob/master/.eslintrc.js

@Gisonrg

Gisonrg commented Jan 17, 2018

Copy link
Copy Markdown
Contributor

Nice one! Can't wait to fix all the style issues in the project :D

Before I merge this, do you think we should use an existing style standard for our eslint?
I am thinking about using either https://github.com/airbnb/javascript or https://github.com/google/eslint-config-google

Feel free to discuss with the team to choose a standard you all agreed on.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

I've used airbnb before. I would prefer airbnb as their docs have the eslint rules which we can ctrl f easily to see an example of.

@damithc

damithc commented Jan 18, 2018

Copy link
Copy Markdown

The common standards for our projects (open for updates) https://github.com/oss-generic/process/blob/master/docs/CodingStandards.adoc

@Gisonrg

Gisonrg commented Jan 18, 2018

Copy link
Copy Markdown
Contributor

Let's use the airbnb preset and modified based on our standard then :P

@nicholaschuayunzhi Can you help us set up the eslint as discussed?

@acjh

acjh commented Jan 18, 2018

Copy link
Copy Markdown
Contributor

The common standards for our projects (open for updates) https://github.com/oss-generic/process/blob/master/docs/CodingStandards.adoc

If a topic is not covered in this document, refer to airbnb JavaScript Style Guide

airbnb it is! Also, teammates-eslint.yml.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

Okay I'll work on it. Need to do some research first.

Also do you want it to be standardized across all the modules?

@Gisonrg

Gisonrg commented Jan 18, 2018

Copy link
Copy Markdown
Contributor

Nice, take you time. Let's start from markbind-cli first, then extend it to markbind (vue modules has different style standard).

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

Changed rules wrt to oss-generic coding standards

Rules that can't be modified with existing eslint rules:

  • Constants named in screaming snake case
  • Prefer higher-level breaks to lower-level breaks. In the example below, the first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.
  • suggestion for ternary expression
    image

Read up on writing custom rules. Is it worth the time? Anyone with experience? Also will add to dev guide on how to set up eslint.

@nicholaschuayunzhi nicholaschuayunzhi force-pushed the eslint branch 2 times, most recently from 1e29438 to e0b6296 Compare January 20, 2018 08:08
@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

I've updated the eslint config as discussed. Disabled func-names rule and added line break style.

@nicholaschuayunzhi nicholaschuayunzhi force-pushed the eslint branch 2 times, most recently from 5c02202 to 621fefd Compare January 20, 2018 08:55
Comment thread .eslintrc.js
"extends": "airbnb-base",
"rules": {
"function-paren-newline": "off",
"func-names": "off",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical (ascii) order:

  • func-names before function-paren-newline
  • FunctionDeclaration before FunctionExpression

Comment thread .eslintrc.js Outdated
"CallExpression": { "arguments": "first" } ,
"FunctionExpression": { "parameters": "first" },
"FunctionDeclaration": { "parameters": "first" },
"MemberExpression": 1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 seems to be the default in indent and is not overridden by airbnb.

@acjh

acjh commented Jan 20, 2018

Copy link
Copy Markdown
Contributor

I took a while to understand why some choices were made.

Perhaps we should document this in the Wiki, together with the setup instructions.

Comment thread .eslintrc.js
"ArrayExpression": "first",
"CallExpression": { "arguments": "first" } ,
"FunctionExpression": { "parameters": "first" },
"FunctionDeclaration": { "parameters": "first" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical (ascii) order:

  • FunctionDeclaration before FunctionExpression

@acjh

acjh commented Jan 20, 2018

Copy link
Copy Markdown
Contributor

Perhaps we should document this in the Wiki, together with the setup instructions.

Maybe not with the setup instructions (seems out-of-place in the Developer Guide).

@nicholaschuayunzhi

nicholaschuayunzhi commented Jan 20, 2018

Copy link
Copy Markdown
Contributor Author

I'm working on the explanation in a separate gist i can link to in the dev guide. Sorry for missing out the previous ordering of keys.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

I've removed ArrayExpression option in indent as the default option (1) account for aligning elements based on 2 spaces of indentation.

I've added the "array-bracket-newline": ["error", { "multiline": true }], to be consistent with airbnb's
object-curly-newline rule, as well as to prevent such code from passing which is not wanted based on nus oss js standard.

let array = [1,
  2,
  3,]

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

I've added a gist for the explanation to the developer guide.

@acjh

acjh commented Jan 20, 2018

Copy link
Copy Markdown
Contributor

to be consistent with airbnb's object-curly-newline rule

I don't see this 🤔

Comment thread .eslintrc.js Outdated
"error",
2,
{
"CallExpression": { "arguments": "first" } ,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space before comma.

@acjh

acjh commented Jan 20, 2018

Copy link
Copy Markdown
Contributor

I've added a gist for the explanation to the developer guide.

Nice. This can be a page in the Wiki. Let's create a sidebar; the current pages need categorisation anyway.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

to be consistent with airbnb's object-curly-newline rule

I don't see this 🤔

Oh dear, i think i saw wrongly. But the rationale still stands to prevent the below from happening.

let array = [1,
  2,
  3,]

Weird though, my linter is firing off that error. Could it be a default rule? https://eslint.org/docs/rules/object-curly-newline

@acjh

acjh commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

Both rules seem to be { "multiline": true } by default.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

Seems when i do not specify array-bracket-newline, it does not fire off any linting error.
image

Need to look into it further.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

In the eslint docs for both rules, seems like array-bracket-newline is not enabled by default.
image

However for object-curly-newline. It is enabled.
image

So i think we should still have the array-bracket-newline rule.

@acjh

acjh commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

Nice catch.

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

I still find it weird though, according to user guide, no rules are enabled by default, but the docs seem to say otherwise.

@nicholaschuayunzhi

nicholaschuayunzhi commented Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

Ok i think i got it, they disabled array-bracket-newline and enabled object-curly-newline in airbnb-base preset. And it is not documented on the readme.

https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js

@nicholaschuayunzhi

nicholaschuayunzhi commented Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

Okay I think it should be ready for review. Note that operator-linebreak is manually enabled as airbnb-base package with enabled operator-linebreak rule is not published yet

I've also removed the line endings rule as airbnb-base already checks for unix endings

@Gisonrg

Gisonrg commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

LGTM, feel free to merge this @acjh

@acjh acjh merged commit ed21d5f into MarkBind:master Jan 21, 2018
@acjh

acjh commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

@nicholaschuayunzhi Thanks for your contribution!

@acjh

acjh commented Jan 22, 2018

Copy link
Copy Markdown
Contributor

@nicholaschuayunzhi Can you create a PR to apply --fix?

@nicholaschuayunzhi

Copy link
Copy Markdown
Contributor Author

@acjh Will do!

@acjh acjh added this to the v1.4.3 milestone Feb 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants