@angular-eslint/eslint-plugin
Advanced tools
Comparing version 18.4.2-alpha.3 to 18.4.2-alpha.4
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@angular-eslint"], | ||
"rules": { | ||
"@angular-eslint/component-class-suffix": "error", | ||
"@angular-eslint/component-max-inline-declarations": "error", | ||
"@angular-eslint/component-selector": "error", | ||
"@angular-eslint/consistent-component-styles": "error", | ||
"@angular-eslint/contextual-decorator": "error", | ||
"@angular-eslint/contextual-lifecycle": "error", | ||
"@angular-eslint/directive-class-suffix": "error", | ||
"@angular-eslint/directive-selector": "error", | ||
"@angular-eslint/no-async-lifecycle-method": "error", | ||
"@angular-eslint/no-attribute-decorator": "error", | ||
"@angular-eslint/no-conflicting-lifecycle": "error", | ||
"@angular-eslint/no-duplicates-in-metadata-arrays": "error", | ||
"@angular-eslint/no-empty-lifecycle-method": "error", | ||
"@angular-eslint/no-forward-ref": "error", | ||
"@angular-eslint/no-host-metadata-property": "error", | ||
"@angular-eslint/no-input-prefix": "error", | ||
"@angular-eslint/no-input-rename": "error", | ||
"@angular-eslint/no-inputs-metadata-property": "error", | ||
"@angular-eslint/no-lifecycle-call": "error", | ||
"@angular-eslint/no-output-native": "error", | ||
"@angular-eslint/no-output-on-prefix": "error", | ||
"@angular-eslint/no-output-rename": "error", | ||
"@angular-eslint/no-outputs-metadata-property": "error", | ||
"@angular-eslint/no-pipe-impure": "error", | ||
"@angular-eslint/no-queries-metadata-property": "error", | ||
"@angular-eslint/pipe-prefix": "error", | ||
"@angular-eslint/prefer-on-push-component-change-detection": "error", | ||
"@angular-eslint/prefer-output-readonly": "error", | ||
"@angular-eslint/prefer-standalone": "error", | ||
"@angular-eslint/prefer-standalone-component": "error", | ||
"@angular-eslint/relative-url-prefix": "error", | ||
"@angular-eslint/require-localize-metadata": "error", | ||
"@angular-eslint/runtime-localize": "error", | ||
"@angular-eslint/sort-lifecycle-methods": "error", | ||
"@angular-eslint/sort-ngmodule-metadata-arrays": "error", | ||
"@angular-eslint/use-component-selector": "error", | ||
"@angular-eslint/use-component-view-encapsulation": "error", | ||
"@angular-eslint/use-injectable-provided-in": "error", | ||
"@angular-eslint/use-lifecycle-interface": "error", | ||
"@angular-eslint/use-pipe-transform-interface": "error" | ||
} | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@angular-eslint"], | ||
"rules": { | ||
"@angular-eslint/component-class-suffix": "error", | ||
"@angular-eslint/component-max-inline-declarations": "error", | ||
"@angular-eslint/component-selector": "error", | ||
"@angular-eslint/consistent-component-styles": "error", | ||
"@angular-eslint/contextual-decorator": "error", | ||
"@angular-eslint/contextual-lifecycle": "error", | ||
"@angular-eslint/directive-class-suffix": "error", | ||
"@angular-eslint/directive-selector": "error", | ||
"@angular-eslint/no-async-lifecycle-method": "error", | ||
"@angular-eslint/no-attribute-decorator": "error", | ||
"@angular-eslint/no-conflicting-lifecycle": "error", | ||
"@angular-eslint/no-duplicates-in-metadata-arrays": "error", | ||
"@angular-eslint/no-empty-lifecycle-method": "error", | ||
"@angular-eslint/no-forward-ref": "error", | ||
"@angular-eslint/no-host-metadata-property": "error", | ||
"@angular-eslint/no-input-prefix": "error", | ||
"@angular-eslint/no-input-rename": "error", | ||
"@angular-eslint/no-inputs-metadata-property": "error", | ||
"@angular-eslint/no-lifecycle-call": "error", | ||
"@angular-eslint/no-output-native": "error", | ||
"@angular-eslint/no-output-on-prefix": "error", | ||
"@angular-eslint/no-output-rename": "error", | ||
"@angular-eslint/no-outputs-metadata-property": "error", | ||
"@angular-eslint/no-pipe-impure": "error", | ||
"@angular-eslint/no-queries-metadata-property": "error", | ||
"@angular-eslint/pipe-prefix": "error", | ||
"@angular-eslint/prefer-on-push-component-change-detection": "error", | ||
"@angular-eslint/prefer-output-readonly": "error", | ||
"@angular-eslint/prefer-standalone": "error", | ||
"@angular-eslint/prefer-standalone-component": "error", | ||
"@angular-eslint/relative-url-prefix": "error", | ||
"@angular-eslint/require-localize-metadata": "error", | ||
"@angular-eslint/runtime-localize": "error", | ||
"@angular-eslint/sort-lifecycle-methods": "error", | ||
"@angular-eslint/sort-ngmodule-metadata-arrays": "error", | ||
"@angular-eslint/use-component-selector": "error", | ||
"@angular-eslint/use-component-view-encapsulation": "error", | ||
"@angular-eslint/use-injectable-provided-in": "error", | ||
"@angular-eslint/use-lifecycle-interface": "error", | ||
"@angular-eslint/use-pipe-transform-interface": "error" | ||
} | ||
} |
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@angular-eslint"], | ||
"rules": { | ||
"@angular-eslint/component-class-suffix": "error", | ||
"@angular-eslint/contextual-lifecycle": "error", | ||
"@angular-eslint/directive-class-suffix": "error", | ||
"@angular-eslint/no-empty-lifecycle-method": "error", | ||
"@angular-eslint/no-input-rename": "error", | ||
"@angular-eslint/no-inputs-metadata-property": "error", | ||
"@angular-eslint/no-output-native": "error", | ||
"@angular-eslint/no-output-on-prefix": "error", | ||
"@angular-eslint/no-output-rename": "error", | ||
"@angular-eslint/no-outputs-metadata-property": "error", | ||
"@angular-eslint/use-pipe-transform-interface": "error", | ||
"@angular-eslint/use-lifecycle-interface": "warn" | ||
} | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@angular-eslint"], | ||
"rules": { | ||
"@angular-eslint/component-class-suffix": "error", | ||
"@angular-eslint/contextual-lifecycle": "error", | ||
"@angular-eslint/directive-class-suffix": "error", | ||
"@angular-eslint/no-empty-lifecycle-method": "error", | ||
"@angular-eslint/no-input-rename": "error", | ||
"@angular-eslint/no-inputs-metadata-property": "error", | ||
"@angular-eslint/no-output-native": "error", | ||
"@angular-eslint/no-output-on-prefix": "error", | ||
"@angular-eslint/no-output-rename": "error", | ||
"@angular-eslint/no-outputs-metadata-property": "error", | ||
"@angular-eslint/use-pipe-transform-interface": "error", | ||
"@angular-eslint/use-lifecycle-interface": "warn" | ||
} | ||
} |
@@ -61,10 +61,2 @@ "use strict"; | ||
} | ||
let isAliasMetadataProperty = false; | ||
if (node.parent && utils_1.ASTUtils.isProperty(node.parent)) { | ||
if (utils_1.ASTUtils.getRawText(node.parent.key) !== 'alias') { | ||
// We're within an Input decorator metadata object, but it is not the alias property | ||
return; | ||
} | ||
isAliasMetadataProperty = true; | ||
} | ||
const aliasName = utils_1.ASTUtils.getRawText(node); | ||
@@ -77,12 +69,54 @@ const propertyName = utils_1.ASTUtils.getRawText(propertyOrMethodDefinition.key); | ||
} | ||
const inputCallExpression = utils_1.ASTUtils.getNearestNodeFrom(node, utils_1.ASTUtils.isCallExpression); | ||
if (inputCallExpression && | ||
utils_2.ASTUtils.isIdentifier(inputCallExpression.callee) && | ||
inputCallExpression.callee.name === 'Input' && | ||
utils_1.ASTUtils.isObjectExpression(inputCallExpression.arguments?.[0])) { | ||
const [firstArg] = inputCallExpression.arguments; | ||
const aliasProperty = firstArg.properties.find((property) => utils_1.ASTUtils.isProperty(property) && | ||
utils_1.ASTUtils.getRawText(property.key) === 'alias'); | ||
if (!aliasProperty) { | ||
return; | ||
// The alias is either a string in the `@Input()` decorator function, | ||
// or a string on an `alias` property that is in an object expression | ||
// that is in the `@Input()` decorator or the `input()` function or the | ||
// `input.required()` function. If it's on the `alias` property, then we | ||
// want to remove that whole property rather than just the string literal. | ||
const stringToRemove = utils_1.ASTUtils.isTemplateElement(node) | ||
? node.parent | ||
: node; | ||
let rangeToRemove = stringToRemove.range; | ||
if (utils_1.ASTUtils.isProperty(stringToRemove.parent)) { | ||
const property = stringToRemove.parent; | ||
rangeToRemove = property.range; | ||
if (utils_1.ASTUtils.isObjectExpression(property.parent)) { | ||
const objectExpression = property.parent; | ||
if (objectExpression.properties.length === 1) { | ||
// The property is the only property in the | ||
// object, so we can remove the whole object. | ||
rangeToRemove = objectExpression.range; | ||
// If the object is in an `input()` function, then | ||
// the object will be the second argument. The first | ||
// argument will be the default value. We need to | ||
// remove the comma after the default value. | ||
const tokenBefore = context.sourceCode.getTokenBefore(objectExpression); | ||
if (tokenBefore && utils_2.ASTUtils.isCommaToken(tokenBefore)) { | ||
rangeToRemove = [tokenBefore.range[0], rangeToRemove[1]]; | ||
} | ||
} | ||
else { | ||
// There are other properties in the object, so we | ||
// can only remove the property. How we remove it | ||
// will depend on where the property is in the object. | ||
const propertyIndex = objectExpression.properties.indexOf(property); | ||
if (propertyIndex < objectExpression.properties.length - 1) { | ||
// The property is not the last one, so we can | ||
// remove everything up to the next property | ||
// which will remove the comma after it. | ||
rangeToRemove = [ | ||
property.range[0], | ||
objectExpression.properties[propertyIndex + 1].range[0], | ||
]; | ||
} | ||
else { | ||
// The property is the last one. If the object has a | ||
// trailing comma, then we want to keep the trailing comma. | ||
// The simplest way to do that is to remove the property | ||
// and the comma that precedes it. | ||
const tokenBefore = context.sourceCode.getTokenBefore(property); | ||
if (tokenBefore && utils_2.ASTUtils.isCommaToken(tokenBefore)) { | ||
rangeToRemove = [tokenBefore.range[0], rangeToRemove[1]]; | ||
} | ||
} | ||
} | ||
} | ||
@@ -94,8 +128,3 @@ } | ||
messageId: 'noInputRename', | ||
fix: (fixer) => { | ||
if (node.parent && isAliasMetadataProperty) { | ||
return fixer.remove(node.parent); | ||
} | ||
return fixer.remove(node); | ||
}, | ||
fix: (fixer) => fixer.removeRange(rangeToRemove), | ||
}); | ||
@@ -110,8 +139,3 @@ } | ||
messageId: 'suggestRemoveAliasName', | ||
fix: (fixer) => { | ||
if (node.parent && isAliasMetadataProperty) { | ||
return fixer.remove(node.parent); | ||
} | ||
return fixer.remove(node); | ||
}, | ||
fix: (fixer) => fixer.removeRange(rangeToRemove), | ||
}, | ||
@@ -121,3 +145,3 @@ { | ||
fix: (fixer) => [ | ||
fixer.remove(node), | ||
fixer.removeRange(rangeToRemove), | ||
fixer.replaceText(propertyOrMethodDefinition.key, aliasName.includes('-') ? `'${aliasName}'` : aliasName), | ||
@@ -124,0 +148,0 @@ ], |
@@ -41,2 +41,47 @@ "use strict"; | ||
const propertyName = utils_1.ASTUtils.getRawText(propertyOrMethodDefinition.key); | ||
// The alias is either a string in the `@Output()` decorator function, | ||
// or a string on an `alias` property that is in an object expression | ||
// that is in the `output()` function. If it's the latter, then we want | ||
// to remove that whole property rather than just the string literal. | ||
const stringToRemove = utils_1.ASTUtils.isTemplateElement(node) | ||
? node.parent | ||
: node; | ||
let rangeToRemove = stringToRemove.range; | ||
if (utils_1.ASTUtils.isProperty(stringToRemove.parent)) { | ||
const property = stringToRemove.parent; | ||
rangeToRemove = property.range; | ||
if (utils_1.ASTUtils.isObjectExpression(property.parent)) { | ||
const objectExpression = property.parent; | ||
if (objectExpression.properties.length === 1) { | ||
// The property is the only property in the | ||
// object, so we can remove the whole object. | ||
rangeToRemove = objectExpression.range; | ||
} | ||
else { | ||
// There are other properties in the object, so we | ||
// can only remove the property. How we remove it | ||
// will depend on where the property is in the object. | ||
const propertyIndex = objectExpression.properties.indexOf(property); | ||
if (propertyIndex < objectExpression.properties.length - 1) { | ||
// The property is not the last one, so we can | ||
// remove everything up to the next property | ||
// which will remove the comma after it. | ||
rangeToRemove = [ | ||
property.range[0], | ||
objectExpression.properties[propertyIndex + 1].range[0], | ||
]; | ||
} | ||
else { | ||
// The property is the last one. If the object has a | ||
// trailing comma, then we want to keep the trailing comma. | ||
// The simplest way to do that is to remove the property | ||
// and the comma that precedes it. | ||
const tokenBefore = context.sourceCode.getTokenBefore(property); | ||
if (tokenBefore && utils_2.ASTUtils.isCommaToken(tokenBefore)) { | ||
rangeToRemove = [tokenBefore.range[0], rangeToRemove[1]]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (aliasName === propertyName) { | ||
@@ -46,3 +91,3 @@ context.report({ | ||
messageId: 'noOutputRename', | ||
fix: (fixer) => fixer.remove(node), | ||
fix: (fixer) => fixer.removeRange(rangeToRemove), | ||
}); | ||
@@ -57,3 +102,3 @@ } | ||
messageId: 'suggestRemoveAliasName', | ||
fix: (fixer) => fixer.remove(node), | ||
fix: (fixer) => fixer.removeRange(rangeToRemove), | ||
}, | ||
@@ -63,3 +108,3 @@ { | ||
fix: (fixer) => [ | ||
fixer.remove(node), | ||
fixer.removeRange(rangeToRemove), | ||
fixer.replaceText(propertyOrMethodDefinition.key, aliasName.includes('-') ? `'${aliasName}'` : aliasName), | ||
@@ -66,0 +111,0 @@ ], |
{ | ||
"name": "@angular-eslint/eslint-plugin", | ||
"version": "18.4.2-alpha.3", | ||
"version": "18.4.2-alpha.4", | ||
"description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide", | ||
@@ -21,7 +21,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"@angular-eslint/bundled-angular-compiler": "18.4.2-alpha.3", | ||
"@angular-eslint/utils": "18.4.2-alpha.3" | ||
"@angular-eslint/utils": "18.4.2-alpha.4", | ||
"@angular-eslint/bundled-angular-compiler": "18.4.2-alpha.4" | ||
}, | ||
"devDependencies": { | ||
"@angular-eslint/test-utils": "18.4.2-alpha.3" | ||
"@angular-eslint/test-utils": "18.4.2-alpha.4" | ||
}, | ||
@@ -28,0 +28,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
192256
3235
+ Added@angular-eslint/bundled-angular-compiler@18.4.2-alpha.4(transitive)
+ Added@angular-eslint/utils@18.4.2-alpha.4(transitive)
- Removed@angular-eslint/bundled-angular-compiler@18.4.2-alpha.3(transitive)
- Removed@angular-eslint/utils@18.4.2-alpha.3(transitive)
Updated@angular-eslint/bundled-angular-compiler@18.4.2-alpha.4