Add the possibility to ignore some constructors in no-new
See original GitHub issueWhat rule do you want to change?
no-new
Does this change cause the rule to produce more or fewer warnings?
- fewer
How will the change be implemented? (New option, new default behavior, etc.)?
- By default all side-effect usages of
new
will be reported, like now - You have the possibility to add constructors to an option, which will then be allowed.
Like:
no-new:
- error
- ignore:
- Vue
Please provide some example code that this change will affect:
We often initialize Vue components with this pattern:
import Component from './components/component';
document.addEventListener('DOMContentLoaded', () => {
const element = document.getElementById('id');
new Vue({
el: element,
components: {
Component,
},
render(createElement) {
return createElement('component', {
props: { ...element.dataset },
});
},
})
})
See our open issues here:
- https://gitlab.com/gitlab-org/gitlab-ce/issues/42783
- https://gitlab.com/gitlab-org/gitlab-ce/issues/42306
What does the rule currently do for this code?
Throw an error. There are several workarounds for this, that are not nice:
- add
eslint-disable
, this really adds up if you have a lot of components. - return the result of
new Vue
in the function, but this makes no sense, as no function caller is actually using it
What will the rule do after it’s changed?
Throw no new error.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Configure autofac to ignore constructors marked as obsolete
I have added it to my AutofacAnswers project on GitHub. ... AutoFac passes the proxy class type to the constructor finder but these ......
Read more >c# - Constructors, Ignore Arguments
Builder Pattern is exact solution to this problem. Especially if the combination of optional and required parameters get big, ...
Read more >Constructor, operator "new" - The Modern JavaScript Tutorial
A new empty object is created and assigned to this . The function body executes. Usually it modifies this , adds new properties...
Read more >Inheritance and the prototype chain - JavaScript | MDN
All constructor functions in JavaScript have a special property called prototype , which works with the new operator. The reference to the ...
Read more >Python Class Constructors: Control Your Object Instantiation
Calling the Point() class constructor creates, initializes, and returns a new instance of the class. This instance is then assigned to the point ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@eslint/eslint-team This needs a champion and one more 👍, thanks!
I could get behind this.
Should we support ignoring just constructor identifier names? I feel it could be a bit more flexible if we instead allowed users to specify AST selectors which we would match against the callee nodes of the NewExpression.
Examples with AST selectors:
[name='Vue']
(ignoresnew Vue()
)[object.name='Backbone']
(ignoresnew Backbone.foo()
for anyfoo
)But the trade-off is that the rule configuration has a little steeper learning curve.