UNPKG

eslint-plugin-react-snob

Version:
118 lines (117 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PARSER_CONFIG = void 0; exports.createInvalidCase = createInvalidCase; exports.createNoInlineStylesInvalidCase = createNoInlineStylesInvalidCase; exports.createDerivedConditionalInvalidCase = createDerivedConditionalInvalidCase; exports.createBooleanPrefixInvalidCase = createBooleanPrefixInvalidCase; exports.createComplexConditionInvalidCase = createComplexConditionInvalidCase; exports.createComponentPropInterfaceNamingInvalidCase = createComponentPropInterfaceNamingInvalidCase; exports.createEventHandlerInvalidCase = createEventHandlerInvalidCase; exports.createValidCase = createValidCase; // Parser configuration for JSX testing exports.PARSER_CONFIG = { languageOptions: { parser: require('@typescript-eslint/parser'), parserOptions: { ecmaFeatures: { jsx: true, }, ecmaVersion: 2020, sourceType: 'module', }, }, }; // Helper function to create invalid test cases function createInvalidCase(code, output, errors) { return { code, errors: errors.map((error) => ({ data: error, messageId: 'requireBraces', })), output, }; } // Helper function to create invalid test cases for no-inline-styles rule function createNoInlineStylesInvalidCase(code) { return { code, errors: [ { messageId: 'noInlineStyle', }, ], }; } // Helper function to create invalid test cases for require-derived-conditional-prefix rule function createDerivedConditionalInvalidCase(code, name, suggested) { return { code, errors: [ { data: { name, suggested, }, messageId: 'derivedConditionalShouldStartWithUnderscore', }, ], }; } // Helper function to create invalid test cases for require-boolean-prefix-is rule function createBooleanPrefixInvalidCase(code, name, prefixes, suggested, options) { return { code, errors: [ { data: { name, prefixes, suggested, }, messageId: 'booleanShouldStartWithPrefix', }, ], ...(options && { options: [options] }), }; } // Helper function to create invalid test cases for no-complex-jsx-conditions rule function createComplexConditionInvalidCase(code, errorCount = 1) { return { code, errors: Array(errorCount).fill({ messageId: 'complexCondition', }), }; } // Helper function to create invalid test cases for component-prop-interface-naming rule function createComponentPropInterfaceNamingInvalidCase(code, actual, component, expected) { return { code, errors: [ { data: { actual, component, expected, }, messageId: 'incorrectPropsInterfaceName', }, ], }; } // Helper function to create invalid test cases for consistent-event-handler-naming rule function createEventHandlerInvalidCase(code, errors) { return { code, errors: errors.map((error) => ({ data: error, messageId: 'incorrectHandlerNaming', })), }; } // Helper function to create valid test cases function createValidCase(code) { return { code }; }