Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed May 21, 2024
2 parents 9ccafd5 + 4de165d commit 2b0b762
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
run: |
yarn --ignore-engines --frozen-lockfile --prefer-offline --ignore-scripts
yarn check-clean-workspace-after-install
npx jest --clearCache
- name: Run parallel distributed tasks for build, typecheck, check-rule-docs, check-rule-lists, lint and test targets
uses: jameshenry/parallel-bash-commands@v1
Expand Down
2 changes: 2 additions & 0 deletions .nx/workflows/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ launch-templates:
uses: 'nrwl/nx-cloud-workflows/main/workflow-steps/install-node-modules/main.yaml'
env:
SKIP_POSTINSTALL: 'true'
- name: Clear Jest Cache
script: 'npx jest --clearCache'
31 changes: 31 additions & 0 deletions packages/eslint-plugin/docs/rules/no-input-rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,37 @@ class Test {
}
```

<br>

---

<br>

#### Default Config

```json
{
"rules": {
"@angular-eslint/no-input-rename": [
"error"
]
}
}
```

<br>

#### ✅ Valid Code

```ts
@Component({
selector: 'foo'
})
class Test {
@Input({ transform: (val) => val ?? '', required: true }) foo!: string;
}
```

</details>

<br>
24 changes: 24 additions & 0 deletions packages/eslint-plugin/src/rules/no-input-rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ export default createESLintRule<Options, MessageIds>({
return;
}

const inputCallExpression = ASTUtils.getNearestNodeFrom(
node,
ASTUtils.isCallExpression,
);

if (
inputCallExpression &&
TSESLintASTUtils.isIdentifier(inputCallExpression.callee) &&
inputCallExpression.callee.name === 'Input' &&
ASTUtils.isObjectExpression(inputCallExpression.arguments?.[0])
) {
const [firstArg] = inputCallExpression.arguments;

const aliasProperty = firstArg.properties.find(
(property) =>
ASTUtils.isProperty(property) &&
ASTUtils.getRawText(property.key) === 'alias',
);

if (!aliasProperty) {
return;
}
}

if (aliasName === propertyName) {
context.report({
node,
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tests/rules/no-input-rename/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export const valid = [
@Input({ required: true }) name: string;
}
`,
`
@Component({
selector: 'foo'
})
class Test {
@Input({ transform: (val) => val ?? '', required: true }) foo!: string;
}
`,
];

export const invalid = [
Expand Down

0 comments on commit 2b0b762

Please sign in to comment.