Skip to content
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

Extract used propTypes detection #1946

Merged
merged 5 commits into from Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/rules/boolean-prop-naming.js
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const has = require('has');
const Components = require('../util/Components');
const propsUtil = require('../util/props');
const docsUrl = require('../util/docsUrl');
Expand Down Expand Up @@ -248,7 +247,7 @@ module.exports = {
}
}

if (!has(list, component) || (list[component].invalidProps || []).length) {
if (list[component].invalidProps && list[component].invalidProps.length > 0) {
reportInvalidNaming(list[component]);
}
});
Expand Down
9 changes: 2 additions & 7 deletions lib/rules/default-props-match-prop-types.js
Expand Up @@ -5,7 +5,6 @@
*/
'use strict';

const has = require('has');
const Components = require('../util/Components');
const variableUtil = require('../util/variable');
const annotations = require('../util/annotations');
Expand Down Expand Up @@ -595,11 +594,7 @@ module.exports = {
stack = null;
const list = components.list();

for (const component in list) {
if (!has(list, component)) {
continue;
}

Object.keys(list).forEach(component => {
// If no defaultProps could be found, we don't report anything.
if (!list[component].defaultProps) {
return;
Expand All @@ -609,7 +604,7 @@ module.exports = {
list[component].propTypes,
list[component].defaultProps || {}
);
}
});
}
};
})
Expand Down
8 changes: 2 additions & 6 deletions lib/rules/display-name.js
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const has = require('has');
const Components = require('../util/Components');
const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
Expand Down Expand Up @@ -216,12 +215,9 @@ module.exports = {
'Program:exit': function() {
const list = components.list();
// Report missing display name for all components
for (const component in list) {
if (!has(list, component) || list[component].hasDisplayName) {
continue;
}
Object.keys(list).filter(component => !list[component].hasDisplayName).forEach(component => {
reportMissingDisplayName(list[component]);
}
});
}
};
})
Expand Down
17 changes: 7 additions & 10 deletions lib/rules/no-multi-comp.js
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const has = require('has');
const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');

Expand Down Expand Up @@ -59,17 +58,15 @@ module.exports = {
}

const list = components.list();
let i = 0;

for (const component in list) {
if (!has(list, component) || isIgnored(list[component]) || ++i === 1) {
continue;
Object.keys(list).filter(component => !isIgnored(list[component])).forEach((component, i) => {
if (i >= 1) {
context.report({
node: list[component].node,
message: MULTI_COMP_MESSAGE
});
}
context.report({
node: list[component].node,
message: MULTI_COMP_MESSAGE
});
}
});
}
};
})
Expand Down
8 changes: 2 additions & 6 deletions lib/rules/no-set-state.js
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const has = require('has');
const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');

Expand Down Expand Up @@ -74,12 +73,9 @@ module.exports = {

'Program:exit': function() {
const list = components.list();
for (const component in list) {
if (!has(list, component) || isValid(list[component])) {
continue;
}
Object.keys(list).filter(component => !isValid(list[component])).forEach(component => {
reportSetStateUsages(list[component]);
}
});
}
};
})
Expand Down