1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /**
- * @fileoverview Forbid certain props on DOM Nodes
- * @author David Vázquez
- */
- 'use strict';
- const docsUrl = require('../util/docsUrl');
- // ------------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------------
- const DEFAULTS = [];
- // ------------------------------------------------------------------------------
- // Rule Definition
- // ------------------------------------------------------------------------------
- module.exports = {
- meta: {
- docs: {
- description: 'Forbid certain props on DOM Nodes',
- category: 'Best Practices',
- recommended: false,
- url: docsUrl('forbid-dom-props')
- },
- schema: [{
- type: 'object',
- properties: {
- forbid: {
- type: 'array',
- items: {
- type: 'string',
- minLength: 1
- },
- uniqueItems: true
- }
- },
- additionalProperties: false
- }]
- },
- create: function(context) {
- function isForbidden(prop) {
- const configuration = context.options[0] || {};
- const forbid = configuration.forbid || DEFAULTS;
- return forbid.indexOf(prop) >= 0;
- }
- return {
- JSXAttribute: function(node) {
- const tag = node.parent.name.name;
- if (!(tag && tag[0] !== tag[0].toUpperCase())) {
- // This is a Component, not a DOM node, so exit.
- return;
- }
- const prop = node.name.name;
- if (!isForbidden(prop)) {
- return;
- }
- context.report({
- node: node,
- message: `Prop \`${prop}\` is forbidden on DOM Nodes`
- });
- }
- };
- }
- };
|