question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow `this` modification in `no-mutation`

See original GitHub issue

As proposed by @scottnonnenberg in https://github.com/jhusain/eslint-plugin-immutable/pull/15, the no-mutation rule could accept mutations to this, as they may make sense in some applications.

To do: Accept mutation of the this object, only if a corresponding flag is set.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jfmengelscommented, Jun 21, 2016

Hmm, not sure it makes sense. If you only allow this to be mutated in the constructor, then you don’t really need it, and you can do it with closures.

function Person(age, firstName, lastName) {
  const isOver18 = age > 18;
  return {
    age: age,
    fullName: function() {
      return firstName + ' ' + lastName;
    }
  };
}

If you have an other use-case for this, I’m happy to hear it 😃

0reactions
deepu105commented, Apr 28, 2017

@jfmengels I was about to open a new issue then I came across this thread, I found this plugin useful and I guess being able to configure mutation of this only inside constructor is somthing thats useful in react apps especially, as you woul often assign this.state = .. in constructor but you wouldnt want to do that outside the constructor as state shouldnt be mutated. so somethink like below might be bit more flexible

"fp/no-mutation": ["error", {
  "commonjs": true,
  "allowThis": true,
  "allowThisInConstructor": true,
  "exceptions": [
    {"object": "foo", "property": "bar"}
  ]
}]

or even better would be if we can just specify method in the exceptions

"fp/no-mutation": ["error", {
  "commonjs": true,
  "allowThis": true,
  "exceptions": [
    {"object": "this", "property": "state", "method": "constructor"}
  ]
}]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Modifications (genetics) - Wikipedia
The term Modifications in genetics refers to both naturally occurring and engineered changes in DNA. Incidental, or natural mutations occur through errors ...
Read more >
Mutation, Repair and Recombination - Genomes - NCBI - NIH
Methylations, for example, often result in modified nucleotides with altered base-pairing properties and so lead to point mutations.
Read more >
Genetic Mutation | Learn Science at Scitable - Nature
A mutation is a heritable change in the nucleotide sequence of an organism's DNA that ultimately serves as a source of genetic diversity....
Read more >
What is a gene variant and how do variants occur?
A gene variant (or mutation) changes the DNA sequence of a gene in a way that makes it different from most people's.
Read more >
New Gene-Editing Technique Offers Scientists Ability to “Turn ...
Targeted mutations to the genome can now be introduced by splitting specific mutator enzymes and then triggering them to reconstitute, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found