UNPKG

eslint-plugin-jsx-secure-form

Version:

Plugin that checks if you fields have spellcheck attribute set to false

45 lines (38 loc) 1.55 kB
/** * @fileoverview Disable spellcheck for all inputs. * @author Dominik Szymanski */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ const elementType = require("jsx-ast-utils/elementType"); const getProp = require("jsx-ast-utils/getProp"); const getLiteralPropValue = require("jsx-ast-utils/getLiteralPropValue"); const constants = require("../consts"); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ const errorMessage = 'You should set "spellcheck" attribute to false due to security reasons'; module.exports = context => ({ JSXOpeningElement: node => { const isInput = elementType(node) === constants.ELEMENT_INPUT_TYPE; if (isInput) { const spellcheckValue = getLiteralPropValue( getProp(node.attributes, constants.SPELLCHECK_PROPERTY) ); const typeValue = getLiteralPropValue( getProp(node.attributes, constants.TYPE_PROPERTY) ); if ( !constants.SKIP_TYPES.includes(typeValue) && spellcheckValue === undefined || spellcheckValue === true ) { context.report({ node, message: errorMessage }); } } } });