eslint-plugin-react-native-accessibility
Advanced tools
Comparing version
@@ -17,3 +17,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -35,3 +35,3 @@ var schemas_1 = require("../util/schemas"); | ||
if (attrName === propName) { | ||
var isExpression = (0, isNodePropExpression_1["default"])(node); | ||
var isExpression = (0, isNodePropExpression_1.default)(node); | ||
if (!isExpression) { | ||
@@ -44,3 +44,3 @@ // ensure we are only checking literal prop values | ||
var validate = attrValue.map(function (strValue) { | ||
return (0, isOneOf_1["default"])(strValue, validValues); | ||
return (0, isOneOf_1.default)(strValue, validValues); | ||
}); | ||
@@ -50,3 +50,3 @@ invalid = validate.indexOf(false) > -1; | ||
else { | ||
invalid = !(0, isOneOf_1["default"])(attrValue, validValues); | ||
invalid = !(0, isOneOf_1.default)(attrValue, validValues); | ||
} | ||
@@ -56,3 +56,3 @@ if (invalid) { | ||
node: node, | ||
message: errorMessage | ||
message: errorMessage, | ||
}); | ||
@@ -63,4 +63,4 @@ } | ||
} | ||
} }, create)); } | ||
} }, create)); }, | ||
}); }; | ||
exports["default"] = createValidPropRule; | ||
exports.default = createValidPropRule; |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable global-require */ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -13,9 +13,29 @@ __assign = Object.assign || function(t) { | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var has_accessibility_hint_1 = __importDefault(require("./rules/has-accessibility-hint")); | ||
var has_accessibility_props_1 = __importDefault(require("./rules/has-accessibility-props")); | ||
var has_important_for_accessibility_1 = __importDefault(require("./rules/has-important-for-accessibility")); | ||
var has_valid_accessibility_actions_1 = __importDefault(require("./rules/has-valid-accessibility-actions")); | ||
var has_valid_accessibility_component_type_1 = __importDefault(require("./rules/has-valid-accessibility-component-type")); | ||
var has_valid_accessibility_descriptors_1 = __importDefault(require("./rules/has-valid-accessibility-descriptors")); | ||
var has_valid_accessibility_ignores_invert_colors_1 = __importDefault(require("./rules/has-valid-accessibility-ignores-invert-colors")); | ||
var has_valid_accessibility_live_region_1 = __importDefault(require("./rules/has-valid-accessibility-live-region")); | ||
var has_valid_accessibility_role_1 = __importDefault(require("./rules/has-valid-accessibility-role")); | ||
var has_valid_accessibility_state_1 = __importDefault(require("./rules/has-valid-accessibility-state")); | ||
var has_valid_accessibility_states_1 = __importDefault(require("./rules/has-valid-accessibility-states")); | ||
var has_valid_accessibility_traits_1 = __importDefault(require("./rules/has-valid-accessibility-traits")); | ||
var has_valid_accessibility_value_1 = __importDefault(require("./rules/has-valid-accessibility-value")); | ||
var has_valid_important_for_accessibility_1 = __importDefault(require("./rules/has-valid-important-for-accessibility")); | ||
var no_nested_touchables_1 = __importDefault(require("./rules/no-nested-touchables")); | ||
var should_touchables_have_label_1 = __importDefault(require("./rules/should-touchables-have-label")); | ||
var defaultConfig = { | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true | ||
} | ||
jsx: true, | ||
}, | ||
}, | ||
plugins: ['react-native-a11y'] | ||
plugins: ['react-native-a11y'], | ||
}; | ||
@@ -34,30 +54,30 @@ var basicRules = { | ||
'react-native-a11y/no-nested-touchables': 'error', | ||
'react-native-a11y/should-touchables-have-label': 'error' | ||
'react-native-a11y/should-touchables-have-label': 'error', | ||
}; | ||
var iOSRules = { | ||
'react-native-a11y/has-valid-accessibility-ignores-invert-colors': 'error', | ||
'react-native-a11y/has-important-for-accessibility': 'error' | ||
'react-native-a11y/has-important-for-accessibility': 'error', | ||
}; | ||
var AndroidRules = { | ||
'react-native-a11y/has-valid-accessibility-live-region': 'error', | ||
'react-native-a11y/has-valid-important-for-accessibility': 'error' | ||
'react-native-a11y/has-valid-important-for-accessibility': 'error', | ||
}; | ||
module.exports = { | ||
exports.default = { | ||
rules: { | ||
'has-accessibility-hint': require('./rules/has-accessibility-hint'), | ||
'has-accessibility-props': require('./rules/has-accessibility-props'), | ||
'has-important-for-accessibility': require('./rules/has-important-for-accessibility'), | ||
'has-valid-accessibility-actions': require('./rules/has-valid-accessibility-actions'), | ||
'has-valid-accessibility-component-type': require('./rules/has-valid-accessibility-component-type'), | ||
'has-valid-accessibility-descriptors': require('./rules/has-valid-accessibility-descriptors'), | ||
'has-valid-accessibility-ignores-invert-colors': require('./rules/has-valid-accessibility-ignores-invert-colors'), | ||
'has-valid-accessibility-live-region': require('./rules/has-valid-accessibility-live-region'), | ||
'has-valid-accessibility-role': require('./rules/has-valid-accessibility-role'), | ||
'has-valid-accessibility-state': require('./rules/has-valid-accessibility-state'), | ||
'has-valid-accessibility-states': require('./rules/has-valid-accessibility-states'), | ||
'has-valid-accessibility-traits': require('./rules/has-valid-accessibility-traits'), | ||
'has-valid-accessibility-value': require('./rules/has-valid-accessibility-value'), | ||
'has-valid-important-for-accessibility': require('./rules/has-valid-important-for-accessibility'), | ||
'no-nested-touchables': require('./rules/no-nested-touchables'), | ||
'should-touchables-have-label': require('./rules/should-touchables-have-label') | ||
'has-accessibility-hint': has_accessibility_hint_1.default, | ||
'has-accessibility-props': has_accessibility_props_1.default, | ||
'has-important-for-accessibility': has_important_for_accessibility_1.default, | ||
'has-valid-accessibility-actions': has_valid_accessibility_actions_1.default, | ||
'has-valid-accessibility-component-type': has_valid_accessibility_component_type_1.default, | ||
'has-valid-accessibility-descriptors': has_valid_accessibility_descriptors_1.default, | ||
'has-valid-accessibility-ignores-invert-colors': has_valid_accessibility_ignores_invert_colors_1.default, | ||
'has-valid-accessibility-live-region': has_valid_accessibility_live_region_1.default, | ||
'has-valid-accessibility-role': has_valid_accessibility_role_1.default, | ||
'has-valid-accessibility-state': has_valid_accessibility_state_1.default, | ||
'has-valid-accessibility-states': has_valid_accessibility_states_1.default, | ||
'has-valid-accessibility-traits': has_valid_accessibility_traits_1.default, | ||
'has-valid-accessibility-value': has_valid_accessibility_value_1.default, | ||
'has-valid-important-for-accessibility': has_valid_important_for_accessibility_1.default, | ||
'no-nested-touchables': no_nested_touchables_1.default, | ||
'should-touchables-have-label': should_touchables_have_label_1.default, | ||
}, | ||
@@ -68,4 +88,4 @@ configs: { | ||
android: __assign(__assign({}, defaultConfig), { rules: __assign(__assign({}, basicRules), AndroidRules) }), | ||
all: __assign(__assign({}, defaultConfig), { rules: __assign(__assign(__assign({}, basicRules), iOSRules), AndroidRules) }) | ||
} | ||
all: __assign(__assign({}, defaultConfig), { rules: __assign(__assign(__assign({}, basicRules), iOSRules), AndroidRules) }), | ||
}, | ||
}; |
@@ -7,3 +7,3 @@ "use strict"; | ||
*/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -15,6 +15,6 @@ // Rule Definition | ||
var schema = (0, schemas_1.generateObjSchema)(); | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
docs: {}, | ||
schema: [schema] | ||
schema: [schema], | ||
}, | ||
@@ -27,7 +27,7 @@ create: function (context) { return ({ | ||
node: node, | ||
message: 'has accessibilityLabel prop but no accessibilityHint' | ||
message: 'has accessibilityLabel prop but no accessibilityHint', | ||
}); | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -18,3 +18,3 @@ var isTouchable_1 = __importDefault(require("../util/isTouchable")); | ||
var deprecatedProps = ['accessibilityTraits', 'accessibilityComponentType']; | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
@@ -28,12 +28,12 @@ docs: {}, | ||
items: { | ||
type: 'string' | ||
type: 'string', | ||
}, | ||
uniqueItems: true | ||
} | ||
uniqueItems: true, | ||
}, | ||
}, | ||
] | ||
], | ||
}, | ||
create: function (context) { return ({ | ||
JSXOpeningElement: function (node) { | ||
if ((0, isTouchable_1["default"])(node, context) && | ||
if ((0, isTouchable_1.default)(node, context) && | ||
(0, jsx_ast_utils_1.hasAnyProp)(node.attributes, deprecatedProps) && | ||
@@ -45,7 +45,7 @@ ((0, jsx_ast_utils_1.hasProp)(node.attributes, 'accessibilityRole') || | ||
node: node, | ||
message: errorMessage((0, jsx_ast_utils_1.elementType)(node)) | ||
message: errorMessage((0, jsx_ast_utils_1.elementType)(node)), | ||
}); | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -8,3 +8,3 @@ var utils_1 = require("@typescript-eslint/utils"); | ||
var errorMessageImportant = 'Missing a11y props. Expected to have importantForAccessibility="no-hide-descendants" for accessibilityElementsHidden={true}'; | ||
module.exports = createRule({ | ||
exports.default = createRule({ | ||
name: 'has-important-for-accessibility', | ||
@@ -15,7 +15,7 @@ defaultOptions: [], | ||
docs: { | ||
description: 'importantForAccessibility and accessibilityElementsHidden should be used together' | ||
description: 'importantForAccessibility and accessibilityElementsHidden should be used together', | ||
}, | ||
messages: { | ||
'missing-a11y-props/importantForAccessibilityAndAccessibilityElementsHidden': errorMessageElementsHidden, | ||
'missing-a11y-props/importantForAccessibility': errorMessageImportant | ||
'missing-a11y-props/importantForAccessibility': errorMessageImportant, | ||
}, | ||
@@ -26,6 +26,6 @@ schema: [ | ||
properties: {}, | ||
required: false | ||
required: false, | ||
}, | ||
], | ||
fixable: 'code' | ||
fixable: 'code', | ||
}, | ||
@@ -48,3 +48,3 @@ create: function (context) { return ({ | ||
node.name.range, ' accessibilityElementsHidden={true}'); | ||
} | ||
}, | ||
}); | ||
@@ -67,8 +67,8 @@ } | ||
node.name.range, ' importantForAccessibility="no-hide-descendants"'); | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -19,4 +19,4 @@ var isNodePropExpression_1 = __importDefault(require("../util/isNodePropExpression")); | ||
var standardActions = [ | ||
'magicTap', | ||
'escape', | ||
'magicTap', // iOS only | ||
'escape', // iOS only | ||
'activate', | ||
@@ -27,6 +27,6 @@ 'increment', | ||
]; | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
docs: {}, | ||
schema: [(0, schemas_1.generateObjSchema)()] | ||
schema: [(0, schemas_1.generateObjSchema)()], | ||
}, | ||
@@ -38,3 +38,3 @@ create: function (context) { return ({ | ||
node: node, | ||
message: message | ||
message: message, | ||
}); | ||
@@ -47,3 +47,3 @@ }; | ||
var handlerProp = (0, jsx_ast_utils_1.getProp)(node.attributes, 'onAccessibilityAction'); | ||
var isHandlerExpression = (0, isNodePropExpression_1["default"])(handlerProp); | ||
var isHandlerExpression = (0, isNodePropExpression_1.default)(handlerProp); | ||
if (!isHandlerExpression) { | ||
@@ -56,3 +56,3 @@ var handlerPropValue = (0, jsx_ast_utils_1.getPropValue)(handlerProp); | ||
var actionsProp = (0, jsx_ast_utils_1.getProp)(node.attributes, 'accessibilityActions'); | ||
var isActionsExpression = (0, isNodePropExpression_1["default"])(actionsProp); | ||
var isActionsExpression = (0, isNodePropExpression_1.default)(actionsProp); | ||
if (!isActionsExpression) { | ||
@@ -91,4 +91,4 @@ var attrValue = (0, jsx_ast_utils_1.getPropValue)(actionsProp); | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -23,2 +23,2 @@ // Rule Definition | ||
]; | ||
module.exports = (0, valid_prop_1["default"])('accessibilityComponentType', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('accessibilityComponentType', validValues, errorMessage); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -25,3 +25,3 @@ // Rule Definition | ||
}; | ||
module.exports = createRule({ | ||
exports.default = createRule({ | ||
name: 'has-valid-accessibility-descriptors', | ||
@@ -33,3 +33,3 @@ defaultOptions: [], | ||
description: 'Ensures that accessible components have appropriate props to communicate with assistive technologies', | ||
url: 'https://example.com/rule-docs' | ||
url: 'https://example.com/rule-docs', | ||
}, | ||
@@ -39,8 +39,8 @@ schema: [schema], | ||
messages: { | ||
missingA11yProps: errorMessage | ||
} | ||
missingA11yProps: errorMessage, | ||
}, | ||
}, | ||
create: function (context) { return ({ | ||
JSXOpeningElement: function (node) { | ||
if ((0, isTouchable_1["default"])(node, context) || (0, jsx_ast_utils_1.elementType)(node) === 'TextInput') { | ||
if ((0, isTouchable_1.default)(node, context) || (0, jsx_ast_utils_1.elementType)(node) === 'TextInput') { | ||
if (!(0, jsx_ast_utils_1.hasAnyProp)(node.attributes, [ | ||
@@ -62,11 +62,11 @@ 'role', | ||
// $FlowFixMe | ||
node.name.range, (0, isTouchable_1["default"])(node, context) | ||
node.name.range, (0, isTouchable_1.default)(node, context) | ||
? ' accessibilityRole="button"' | ||
: ' accessibilityLabel={}'); | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}); |
@@ -14,3 +14,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -28,3 +28,3 @@ // Rule Definition | ||
return (0, jsx_ast_utils_1.hasProp)(attributes, propName) && | ||
(0, isNodePropValueBoolean_1["default"])((0, jsx_ast_utils_1.getProp)(attributes, propName)); | ||
(0, isNodePropValueBoolean_1.default)((0, jsx_ast_utils_1.getProp)(attributes, propName)); | ||
}; | ||
@@ -47,3 +47,3 @@ var checkParent = function (_a) { | ||
enableLinting: true, | ||
elementsToCheck: defaultInvertableComponents | ||
elementsToCheck: defaultInvertableComponents, | ||
}; | ||
@@ -70,9 +70,9 @@ // Escape hatch for tests | ||
}; | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
docs: {}, | ||
schema: [schema] | ||
schema: [schema], | ||
}, | ||
functions: { | ||
verifyReactNativeImage: verifyReactNativeImage | ||
verifyReactNativeImage: verifyReactNativeImage, | ||
}, | ||
@@ -102,6 +102,6 @@ create: function (_a) { | ||
if ((0, jsx_ast_utils_1.hasProp)(openingElement.attributes, propName) && | ||
!(0, isNodePropValueBoolean_1["default"])((0, jsx_ast_utils_1.getProp)(openingElement.attributes, propName))) { | ||
!(0, isNodePropValueBoolean_1.default)((0, jsx_ast_utils_1.getProp)(openingElement.attributes, propName))) { | ||
report({ | ||
node: node, | ||
message: 'accessibilityIgnoresInvertColors prop is not a boolean value' | ||
message: 'accessibilityIgnoresInvertColors prop is not a boolean value', | ||
}); | ||
@@ -127,3 +127,3 @@ } | ||
node: node, | ||
message: 'Found an element which will be inverted. Add the accessibilityIgnoresInvertColors prop' | ||
message: 'Found an element which will be inverted. Add the accessibilityIgnoresInvertColors prop', | ||
}); | ||
@@ -133,6 +133,6 @@ } | ||
} | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
var templateObject_1, templateObject_2; |
@@ -11,3 +11,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -19,2 +19,2 @@ // Rule Definition | ||
var validValues = ['none', 'polite', 'assertive']; | ||
module.exports = (0, valid_prop_1["default"])('accessibilityLiveRegion', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('accessibilityLiveRegion', validValues, errorMessage); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var valid_prop_1 = __importDefault(require("../factory/valid-prop")); | ||
@@ -52,2 +52,2 @@ // ---------------------------------------------------------------------------- | ||
]; | ||
module.exports = (0, valid_prop_1["default"])('accessibilityRole', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('accessibilityRole', validValues, errorMessage); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -21,7 +21,7 @@ var schemas_1 = require("../util/schemas"); | ||
var errorMessageRadio = 'Missing a11y props. Expected one of: accessibilityState '; | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
docs: {}, | ||
schema: [(0, schemas_1.generateObjSchema)()], | ||
fixable: 'whitespace' | ||
fixable: 'whitespace', | ||
}, | ||
@@ -41,3 +41,3 @@ create: function (context) { return ({ | ||
node: node, | ||
message: message | ||
message: message, | ||
}); | ||
@@ -50,3 +50,3 @@ }; | ||
else if (statePropType === 'ObjectExpression') { | ||
var stateValue = (0, getPropValue_1["default"])(stateProp_1); | ||
var stateValue = (0, getPropValue_1.default)(stateProp_1); | ||
Object.entries(stateValue).map(function (_a) { | ||
@@ -80,3 +80,3 @@ var key = _a[0], value = _a[1]; | ||
if ((0, jsx_ast_utils_1.hasProp)(node.attributes, 'accessibilityState')) { | ||
var state = (0, getPropValue_1["default"])((0, jsx_ast_utils_1.getProp)(node.attributes, 'accessibilityState')); | ||
var state = (0, getPropValue_1.default)((0, jsx_ast_utils_1.getProp)(node.attributes, 'accessibilityState')); | ||
if (!state) { | ||
@@ -90,3 +90,3 @@ context.report({ | ||
node.name.range, ' accessibilityState={}'); | ||
} | ||
}, | ||
}); | ||
@@ -102,3 +102,3 @@ } | ||
node.name.range, ' accessibilityState={}'); | ||
} | ||
}, | ||
}); | ||
@@ -114,3 +114,3 @@ } | ||
node.name.range, ' accessibilityState={}'); | ||
} | ||
}, | ||
}); | ||
@@ -127,3 +127,3 @@ } | ||
node.name.range, ' accessibilityState={}'); | ||
} | ||
}, | ||
}); | ||
@@ -133,4 +133,4 @@ } | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var valid_prop_1 = __importDefault(require("../factory/valid-prop")); | ||
@@ -18,2 +18,2 @@ // ---------------------------------------------------------------------------- | ||
var validValues = ['selected', 'disabled', '']; | ||
module.exports = (0, valid_prop_1["default"])('accessibilityStates', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('accessibilityStates', validValues, errorMessage); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var valid_prop_1 = __importDefault(require("../factory/valid-prop")); | ||
@@ -36,2 +36,2 @@ // ---------------------------------------------------------------------------- | ||
]; | ||
module.exports = (0, valid_prop_1["default"])('accessibilityTraits', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('accessibilityTraits', validValues, errorMessage); |
@@ -7,3 +7,3 @@ "use strict"; | ||
*/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -15,6 +15,6 @@ var schemas_1 = require("../util/schemas"); | ||
var PROP_NAME = 'accessibilityValue'; | ||
module.exports = { | ||
exports.default = { | ||
meta: { | ||
docs: {}, | ||
schema: [(0, schemas_1.generateObjSchema)()] | ||
schema: [(0, schemas_1.generateObjSchema)()], | ||
}, | ||
@@ -34,3 +34,3 @@ create: function (context) { return ({ | ||
node: node, | ||
message: message | ||
message: message, | ||
}); | ||
@@ -81,4 +81,4 @@ }; | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -18,2 +18,2 @@ // Rule Definition | ||
var validValues = ['auto', 'yes', 'no', 'no-hide-descendants']; | ||
module.exports = (0, valid_prop_1["default"])('importantForAccessibility', validValues, errorMessage); | ||
exports.default = (0, valid_prop_1.default)('importantForAccessibility', validValues, errorMessage); |
@@ -9,3 +9,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -22,3 +22,3 @@ // Rule Definition | ||
var createRule = utils_1.ESLintUtils.RuleCreator(function () { return 'https://example.com/rule-docs'; }); | ||
module.exports = createRule({ | ||
exports.default = createRule({ | ||
name: 'no-nested-touchables', | ||
@@ -28,9 +28,9 @@ defaultOptions: [], | ||
docs: { | ||
description: 'Enforce if a view has accessible={true}, that there are no clickable elements inside' | ||
description: 'Enforce if a view has accessible={true}, that there are no clickable elements inside', | ||
}, | ||
messages: { | ||
noNested: errorMessage | ||
noNested: errorMessage, | ||
}, | ||
schema: [schema], | ||
type: 'problem' | ||
type: 'problem', | ||
}, | ||
@@ -55,9 +55,20 @@ create: function (context) { | ||
var accessible = (0, jsx_ast_utils_1.getPropValue)(accessibleProp); | ||
if (accessible || (0, isTouchable_1["default"])(node, context)) { | ||
var clickableChild = (0, findChild_1["default"])(parent, function (child) { | ||
if (accessible || (0, isTouchable_1.default)(node, context)) { | ||
var clickableChild = (0, findChild_1.default)(parent, function (child) { | ||
if (parent.openingElement === child) { | ||
return false; | ||
} | ||
if ((0, isTouchable_1["default"])(child, context) || | ||
if ((0, isTouchable_1.default)(child, context) || | ||
(0, jsx_ast_utils_1.elementType)(child) === 'Button') { | ||
var accessibleProp_1 = (0, jsx_ast_utils_1.getProp)(child.attributes, 'accessible'); | ||
var accessible_1 = (0, jsx_ast_utils_1.getPropValue)(accessibleProp_1); | ||
if (accessible_1 === false) { | ||
return false; | ||
} | ||
var importantForAccessibilityProp = (0, jsx_ast_utils_1.getProp)(child.attributes, 'importantForAccessibility'); | ||
var importantForAccessibility = (0, jsx_ast_utils_1.getPropValue)(importantForAccessibilityProp); | ||
if (importantForAccessibility === 'no-hide-descendants' || | ||
importantForAccessibility === 'no') { | ||
return false; | ||
} | ||
var elType = (0, jsx_ast_utils_1.elementType)(child); | ||
@@ -72,9 +83,9 @@ if (importedComponents.has(elType)) { | ||
node: node, | ||
messageId: 'noNested' | ||
messageId: 'noNested', | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}); |
@@ -9,3 +9,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// ---------------------------------------------------------------------------- | ||
@@ -22,3 +22,3 @@ // Rule Definition | ||
var schema = (0, schemas_1.generateObjSchema)(); | ||
module.exports = createRule({ | ||
exports.default = createRule({ | ||
name: 'should-touchables-have-label', | ||
@@ -30,13 +30,13 @@ defaultOptions: [], | ||
description: 'Enforce accessible labels on touchable elements', | ||
url: 'https://example.com/rule-docs' | ||
url: 'https://example.com/rule-docs', | ||
}, | ||
messages: { | ||
missingProps: errorMessage | ||
missingProps: errorMessage, | ||
}, | ||
schema: [schema], | ||
fixable: 'whitespace' | ||
fixable: 'whitespace', | ||
}, | ||
create: function (context) { return ({ | ||
JSXOpeningElement: function (node) { | ||
if (!(0, isTouchable_1["default"])(node, context)) { | ||
if (!(0, isTouchable_1.default)(node, context)) { | ||
return; | ||
@@ -54,3 +54,3 @@ } | ||
var parent = node.parent; | ||
var textElements = (0, findChild_1["default"])(parent, function (child) { | ||
var textElements = (0, findChild_1.default)(parent, function (child) { | ||
return ((0, jsx_ast_utils_1.elementType)(child) === 'Text' || | ||
@@ -66,3 +66,3 @@ (0, jsx_ast_utils_1.elementType)(child) === 'TextInput' || | ||
data: { | ||
description: 'In some situations, it is necessary to add an accessibilityLabel to a touchable element that does not contain any text. This is because screen readers may not be able to determine the purpose of the element without a label. If another component handling this disable it' | ||
description: 'In some situations, it is necessary to add an accessibilityLabel to a touchable element that does not contain any text. This is because screen readers may not be able to determine the purpose of the element without a label. If another component handling this disable it', | ||
}, | ||
@@ -73,7 +73,7 @@ fix: function (fixer) { | ||
node.name.range, ' accessibilityLabel={}'); | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
}); } | ||
}, | ||
}); }, | ||
}); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @flow | ||
@@ -58,6 +58,17 @@ var utils_1 = require("@typescript-eslint/utils"); | ||
} | ||
else if (utils_1.AST_NODE_TYPES.LogicalExpression === (child === null || child === void 0 ? void 0 : child.type)) { | ||
for (var _b = 0, _c = [child.left, child.right]; _b < _c.length; _b++) { | ||
var element = _c[_b]; | ||
if (element) { | ||
var foundChild = findChild(element, callback); | ||
if (foundChild) { | ||
return foundChild; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
exports["default"] = findChild; | ||
exports.default = findChild; | ||
function findChildInArray(_a, callback) { | ||
@@ -64,0 +75,0 @@ var elements = _a.elements; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ALLOWED_TYPES = [ | ||
@@ -16,2 +16,2 @@ 'Identifier', | ||
} | ||
exports["default"] = isattrPropExpression; | ||
exports.default = isattrPropExpression; |
@@ -5,3 +5,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isNodePropExpression_1 = __importDefault(require("./isNodePropExpression")); | ||
@@ -15,3 +15,3 @@ function isattrPropValueBoolean(attr) { | ||
*/ | ||
var isExpression = (0, isNodePropExpression_1["default"])(attr); | ||
var isExpression = (0, isNodePropExpression_1.default)(attr); | ||
if (isExpression || attr.value === null) { | ||
@@ -34,2 +34,2 @@ // we can't determine the resulting value type of JSXExpressions | ||
} | ||
exports["default"] = isattrPropValueBoolean; | ||
exports.default = isattrPropValueBoolean; |
@@ -7,3 +7,3 @@ "use strict"; | ||
*/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// should be expanded to work with more than just strings | ||
@@ -16,2 +16,2 @@ // as and when it's needed | ||
} | ||
exports["default"] = isOneOf; | ||
exports.default = isOneOf; |
@@ -16,3 +16,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsx_ast_utils_1 = require("jsx-ast-utils"); | ||
@@ -26,3 +26,3 @@ var defaultTouchables = { | ||
TouchableBounce: true, | ||
Pressable: true | ||
Pressable: true, | ||
}; | ||
@@ -35,7 +35,7 @@ function isTouchable(element, context) { | ||
getSourceCode: function () { return ({ | ||
text: '' | ||
text: '', | ||
}); }, | ||
sourceCode: { | ||
text: '' | ||
} | ||
text: '', | ||
}, | ||
}; } | ||
@@ -52,2 +52,2 @@ var options = context.options; | ||
} | ||
exports["default"] = isTouchable; | ||
exports.default = isTouchable; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateObjSchema = exports.enumArraySchema = exports.arraySchema = void 0; | ||
@@ -10,6 +10,6 @@ /** | ||
items: { | ||
type: 'string' | ||
type: 'string', | ||
}, | ||
uniqueItems: true, | ||
additionalItems: false | ||
additionalItems: false, | ||
}; | ||
@@ -25,5 +25,5 @@ /** | ||
type: 'string', | ||
"enum": enumeratedList | ||
enum: enumeratedList, | ||
}, | ||
minItems: minItems | ||
minItems: minItems, | ||
}); | ||
@@ -40,5 +40,5 @@ }; | ||
type: 'object', | ||
properties: properties | ||
properties: properties, | ||
}); | ||
}; | ||
exports.generateObjSchema = generateObjSchema; |
{ | ||
"name": "eslint-plugin-react-native-accessibility", | ||
"version": "3.6.3", | ||
"version": "3.6.4", | ||
"description": "React Native specific accessibility linting rules.", | ||
@@ -24,4 +24,4 @@ "keywords": [ | ||
"lint:fix": "npm run lint -- --fix", | ||
"lint": "eslint --config .eslintrc src __tests__ scripts", | ||
"prepublishOnly": "", | ||
"lint": "eslint src/**/*.ts __tests__ scripts", | ||
"prepublishOnly": "yarn lint && yarn build", | ||
"pretest": "npm run lint:fix && npm run flow", | ||
@@ -40,7 +40,8 @@ "test": "npm run jest", | ||
"@svitejs/changesets-changelog-github-compact": "^1.1.0", | ||
"@typescript-eslint/eslint-plugin": "^8.32.0", | ||
"@typescript-eslint/parser": "^8.32.0", | ||
"babel-jest": "^27.3.1", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-flowtype": "^7.0.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint": "^9.26.0", | ||
"eslint-config-prettier": "^10.1.5", | ||
"eslint-plugin-prettier": "^5.4.0", | ||
"expect": "^27.3.1", | ||
@@ -53,3 +54,3 @@ "flow-bin": "^0.137.0", | ||
"object.assign": "^4.1.2", | ||
"prettier": "^2.4.1", | ||
"prettier": "^3.5.3", | ||
"rimraf": "^3.0.2", | ||
@@ -56,0 +57,0 @@ "safe-publish-latest": "^2.0.0", |
#!/usr/bin/env node --harmony | ||
/* eslint-disable @typescript-eslint/no-require-imports */ | ||
const path = require('path'); | ||
@@ -58,3 +59,3 @@ const fs = require('fs'); | ||
if (error) { | ||
console.error(`exec error: ${error}`); // eslint-disable-line no-console | ||
console.error(`exec error: ${error}`); | ||
} | ||
@@ -61,0 +62,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1080756
25.4%1568
4.81%24
4.35%40
-2.44%