rxjs-tslint-rules icon indicating copy to clipboard operation
rxjs-tslint-rules copied to clipboard

More Observable naming convention options

Open ChrisMBarr opened this issue 5 years ago • 2 comments

Background

Right now Observables can either be enforced to use Finnish notation via the rxjs-finnish rule, or disallowed from using Finnish notation via the rxjs-no-finnish rule.

On the other end, the rxjs-suffix-subjects rule allows for Subjects to have a configurable suffix.

My Situation

After naming all Observables and methods that return them using Finnish notation, my manager tells me he thinks this is dumb and wants me to change them all to use a differet suffix. For example getData$() becomes getDataObs(). I don't love it, but I need to do it.

Rule Suggestion

I'd love it if the rules around allowing/disallowing Finnish notation were combined into a single rule, with an additional option to allow for a custom suffix.

Config Ideas/Examples

Enforce Finnish notation

"rxjs-observable-suffix": {
  "options: "finnish"
}

or

"rxjs-observable-suffix": {
  "options": [{
    "parameters": true,
    "properties": true,
    "suffix": "$",
    "variables": true
  }],
}

Disallow Finnish notation

"rxjs-observable-suffix": {
  "options: "no-finnish"
}

Custom Suffix

"rxjs-observable-suffix": {
  "options": {
    "suffix": "Obs"
  }
}

or

"rxjs-observable-suffix": {
  "options": [{
    "parameters": true,
    "properties": true,
    "suffix": "Obs",
    "variables": true
  }],
}

ChrisMBarr avatar Apr 30 '19 18:04 ChrisMBarr

The thing is that I don't use the Finnish rule or the subject-suffix rule.

I wrote the Finnish rule only because I, at first, thought it would be too hard when someone requested it, but later came up with a simple approach. And Maggie wrote the suffix rule.

Given that an observable suffix rule would essentially be the same implementation as the Finnish rule - but it would have to figure out whether or not subjects should be handled differently - it might be something that you or someone else might like to implement. I have other priorities and I cannot see myself implementing it anytime soon.

cartant avatar Apr 30 '19 20:04 cartant

I will keep it in mind, I have experience writing a few rules for the base TSLint project, but it's been a while and I won't have any time to look into this in the near future.

For now I'll just be enabling the rxjs-no-finnish rule and just remember to add the desired suffix for now. Luckily an initial find & replace was easy since $ wasn't used in too many places!

ChrisMBarr avatar May 01 '19 13:05 ChrisMBarr