eslint-plugin-logical-properties
Version:
15 lines (14 loc) • 719 B
JavaScript
import { getValidPropertyName } from '../utils/getValidPropertyName.js';
export const generateDirectionalPropertyError = (source, target) => `${source} should be replaced with ${target}`;
export const directionalMappingTransformerFactory = ({ node, context, config: { mappings = {}, }, }) => (property) => {
const propertyName = getValidPropertyName(property);
const [source, target] = [propertyName, mappings[propertyName]];
const value = context.sourceCode.getText(property.value);
context.report({
node: node,
message: generateDirectionalPropertyError(source, target),
fix(fixer) {
return fixer.replaceText(property, `"${target}":${value}`);
},
});
};