-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce install size by 30% #2876
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
'use strict'; | ||
|
||
const fromEntries = require('object.fromentries'); | ||
const entries = require('object.entries'); | ||
|
||
/* eslint-disable global-require */ | ||
const allRules = { | ||
'boolean-prop-naming': require('./lib/rules/boolean-prop-naming'), | ||
|
@@ -97,8 +94,14 @@ const allRules = { | |
}; | ||
/* eslint-enable */ | ||
|
||
const fromEntries = Object.fromEntries || function fromEntries(entries) { | ||
const obj = {}; | ||
for (const [key, value] of entries) obj[key] = value; | ||
return obj; | ||
} | ||
Comment on lines
+97
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inlining a polyfill (one that's not matching the spec) is a nonstarter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not rewrite it to avoid the expensive polyfill then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The polyfill isn't expensive, it's the cheapest possible way to correctly implement the method. |
||
|
||
function filterRules(rules, predicate) { | ||
return fromEntries(entries(rules).filter((entry) => predicate(entry[1]))); | ||
return fromEntries(Object.entries(rules).filter((entry) => predicate(entry[1]))); | ||
} | ||
|
||
function configureAsError(rules) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ | |
'use strict'; | ||
|
||
const doctrine = require('doctrine'); | ||
const arrayIncludes = require('array-includes'); | ||
const values = require('object.values'); | ||
Comment on lines
-9
to
-10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. node 4 also lacks these functions. |
||
|
||
const variableUtil = require('./variable'); | ||
const pragmaUtil = require('./pragma'); | ||
|
@@ -562,7 +560,7 @@ function componentRule(rule, context) { | |
*/ | ||
getDetectedComponents() { | ||
const list = components.list(); | ||
return values(list).filter((val) => { | ||
return Object.values(list).filter((val) => { | ||
if (val.node.type === 'ClassDeclaration') { | ||
return true; | ||
} | ||
|
@@ -590,7 +588,7 @@ function componentRule(rule, context) { | |
nodeWrapsComponent(node) { | ||
const childComponent = this.getNameOfWrappedComponent(node.arguments); | ||
const componentList = this.getDetectedComponents(); | ||
return !!childComponent && arrayIncludes(componentList, childComponent); | ||
return !!childComponent && componentList.includes(childComponent); | ||
}, | ||
|
||
isPragmaComponentWrapper(node) { | ||
|
@@ -600,11 +598,11 @@ function componentRule(rule, context) { | |
const propertyNames = ['forwardRef', 'memo']; | ||
const calleeObject = node.callee.object; | ||
if (calleeObject && node.callee.property) { | ||
return arrayIncludes(propertyNames, node.callee.property.name) | ||
return propertyNames.includes(node.callee.property.name) | ||
&& calleeObject.name === pragma | ||
&& !this.nodeWrapsComponent(node); | ||
} | ||
return arrayIncludes(propertyNames, node.callee.name) && this.isDestructuredFromPragmaImport(node.callee.name); | ||
return propertyNames.includes(node.callee.name) && this.isDestructuredFromPragmaImport(node.callee.name); | ||
}, | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this plugin supports node 4, which lacks Object.entries, so we still need the polyfill.