peopledoc / eslint-config-peopledoc

ESLint config for PeopleDoc frontend projects
MIT License
1 stars 1 forks source link

Always a space after `function` keyword #56

Closed ryuran closed 4 years ago

ryuran commented 4 years ago

I propose this rule to identify clearly anonymous function and keep it consistent.

OK :

function () { /*…*/ }
function notAnonymous() { /*…*/ }
async () => { /*…*/ }

KO :

function() { /*…*/ }
async() => { /*…*/ }
    'space-before-function-paren': ['error', {
      anonymous: 'always',
      named: 'never',
      asyncArrow: 'always'
    }],
MrChocolatine commented 4 years ago

Relates to #39 .

MrChocolatine commented 4 years ago

+1 to the proposition. Whitespaces are good and not evil.

Pixelik commented 4 years ago

I don't want to have to remember of this small difference while I code:

function ()
function something()
MrChocolatine commented 4 years ago

It helps identifying anonymous and named functions.

Also, with our current recommendations, something kind of contradictory regarding generator functions:

function* myfunc() {} // Valid

let myfunc = function* () {} // Valid. Space required, but why this time hum?

let myfunc = function*() {} // The linter complains for a missing space
ryuran commented 4 years ago

@Pixelik I don't see any difference if in my mind the rule is "always a space after function" or "always a space before the function name even if it is missing"

If name is missing the space mark the difference between the name and the function keyword. This rules make anonymous function more identifiable.

I can't and I don't want remember every lint rules. It's why I use tools to check and fix it. Like me you can use a formatter or eslint --fix command to manage it.

So "I don't want to have to remember" is not really an argument.

We only need a rule to follow to keep the code consistent.

Valid argument pro:

Valid argument cons: