Comments (8)
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 :)
from eslint-plugin-fp.
@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"}
]
}]
from eslint-plugin-fp.
Maybe this should have an option to allow this
just inside constructors (like how final fields work in Java). 😄
from eslint-plugin-fp.
As you guessed on the original issue, I wanted support for this
for React apps. Without it, as soon as you need to keep hold of a ref
for some reason, you resort to eslint-disable
. If it's not that common, maybe those exceptions are adequate.
from eslint-plugin-fp.
@scottnonnenberg I haven't used React for a while, and haven't got far enough as to play with refs
. Do you mind giving me an example of that use-case?
from eslint-plugin-fp.
Straight from my GatsbyJS-based blog:
componentDidMount() {
catchLinks(this.parentNode, href => this.context.router.push(href));
}
getParent(ref) {
this.parentNode = ref; // eslint-disable-line
}
render() {
return <div ref={this.getParent} />;
}
from eslint-plugin-fp.
Thanks!
Ok, I'll add a this
exception behind a flag.
By the way, you should try to avoid using eslint-disable-line
without specifying the rules to ignore, as you might hide useful reports. See https://github.com/sindresorhus/eslint-plugin-xo/blob/master/docs/rules/no-abusive-eslint-disable.md :)
from eslint-plugin-fp.
Added in 69982ad, and landed in 1.3.0
. Thanks folks!
from eslint-plugin-fp.
Related Issues (20)
- non-mutating slice reverse HOT 1
- Add more options for `no-unused-expression` rule HOT 1
- no-nil false positive
- merge eslint-plugin-better rule into eslint-plugin-fp HOT 2
- document the difference between no-unused-expressions
- CI build failing on Node 4
- no-nil false positive on switch statements HOT 1
- no-mutating-assign with any expression HOT 3
- (fp/no-nil) rule for callbacks? HOT 5
- Upgrade Lodash to avoid `npm update` security issue HOT 1
- fp/no-unused-expression for Node debug
- proposal: rule for limit arguments in function call
- fp/no-nil
- no-mutation and HTML DOM
- no-mutating-methods allowedObjects doesn't work if chained
- ESLint v6 HOT 4
- Fails when run in Jest via ESLint Node.js API
- Support ESLint 8.x HOT 3
- `fp/no-unused-expression` with `'use strict'` HOT 1
- `fp/no-throw`: Option to ignore inside `try`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-fp.