You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
/**
|
|
* @fileoverview Prevent React to be marked as unused
|
|
* @author Glen Mailer
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const pragmaUtil = require('../util/pragma');
|
|
const docsUrl = require('../util/docsUrl');
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
// ------------------------------------------------------------------------------
|
|
|
|
module.exports = {
|
|
meta: {
|
|
docs: {
|
|
description: 'Prevent React to be marked as unused',
|
|
category: 'Best Practices',
|
|
recommended: true,
|
|
url: docsUrl('jsx-uses-react')
|
|
},
|
|
schema: []
|
|
},
|
|
|
|
create(context) {
|
|
const pragma = pragmaUtil.getFromContext(context);
|
|
const fragment = pragmaUtil.getFragmentFromContext(context);
|
|
|
|
function handleOpeningElement() {
|
|
context.markVariableAsUsed(pragma);
|
|
}
|
|
// --------------------------------------------------------------------------
|
|
// Public
|
|
// --------------------------------------------------------------------------
|
|
|
|
return {
|
|
JSXOpeningElement: handleOpeningElement,
|
|
JSXOpeningFragment: handleOpeningElement,
|
|
JSXFragment() {
|
|
context.markVariableAsUsed(fragment);
|
|
}
|
|
};
|
|
}
|
|
};
|