eslint-plugin-flowtype
Advanced tools
Comparing version
@@ -74,2 +74,52 @@ 'use strict'; | ||
var variances = { | ||
minus: '-', | ||
plus: '+' | ||
}; | ||
var generateOrderedList = function generateOrderedList(context, sort, properties) { | ||
return properties.map(function (property) { | ||
var name = (0, _utilities.getParameterName)(property, context); | ||
var value = void 0; | ||
if (property.value.type === 'ObjectTypeAnnotation') { | ||
value = generateFix(property.value, context, sort); // eslint-disable-line no-use-before-define | ||
} else { | ||
value = context.getSourceCode().getText(property.value); | ||
} | ||
return [(variances[property.variance] || '') + name + (property.optional ? '?' : ''), value]; | ||
}).sort(function (first, second) { | ||
return sort(first[0], second[0]) ? -1 : 1; | ||
}).map(function (item) { | ||
return item[0] + ': ' + item[1]; | ||
}); | ||
}; | ||
var generateFix = function generateFix(node, context, sort) { | ||
// this could be done much more cleanly in ESLint >=4 | ||
// as we can apply multiple fixes. That also means we can | ||
// maintain code style in a much nicer way | ||
var nodeText = void 0; | ||
var newTypes = generateOrderedList(context, sort, node.properties); | ||
var source = context.getSourceCode(node); | ||
var originalSubstring = source.getText(node); | ||
nodeText = originalSubstring; | ||
node.properties.forEach(function (property, index) { | ||
var subString = source.getText(property); | ||
var addComma = subString[subString.length - 1] === ','; | ||
nodeText = nodeText.replace(subString, '$' + index + (addComma ? ',' : '')); | ||
}); | ||
newTypes.forEach(function (item, index) { | ||
nodeText = nodeText.replace('$' + index, item); | ||
}); | ||
return nodeText; | ||
}; | ||
var create = function create(context) { | ||
@@ -110,2 +160,7 @@ var order = _lodash2.default.get(context, ['options', 0], 'asc'); | ||
}, | ||
fix(fixer) { | ||
var nodeText = generateFix(node, context, isValidOrder); | ||
return fixer.replaceText(node, nodeText); | ||
}, | ||
loc: identifierNode.loc, | ||
@@ -112,0 +167,0 @@ message: 'Expected type annotations to be in {{natural}}{{insensitive}}{{order}}ending order. "{{current}}" should be before "{{last}}".', |
@@ -56,3 +56,3 @@ { | ||
}, | ||
"version": "2.37.0" | ||
"version": "2.38.0" | ||
} |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
180159
1.68%2184
2.01%3833
0.52%