Skip to content

Commit

Permalink
Remove non-null assertions using the ! postfix operator (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 12, 2024
1 parent a301bf9 commit bf76ad1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-chefs-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Remove non-null assertions using the `!` postfix operator
1 change: 0 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"style": {
"noNamespace": "error",
"noNonNullAssertion": "off",
"noUnusedTemplateLiteral": "off",
"useConsistentArrayType": {
"level": "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getRequireDeclaratorsWithProperty = (

if (declaratorId.type === "Identifier") {
const declaratorIdName = declaratorId.name;
if (declaratorInit!.type === "MemberExpression") {
if (declaratorInit?.type === "MemberExpression") {
const importedName = (declaratorInit.property as Identifier).name;
if (localName === declaratorIdName && identifierName === importedName) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const getDefaultName = (packageName: string) =>
// biome-ignore lint/style/noNonNullAssertion: This is a valid assertion
["AWS", ...packageName.split("/").pop()!.split("-")].join("_");
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getImportSpecifiers = (
const importedName = specifier.imported.name;
importSpecifiers.add({
importedName,
localName: specifier.local!.name || importedName,
localName: specifier.local?.name || importedName,
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getImportSpecifiers = (

if (declaratorId.type === "Identifier") {
const declaratorIdName = declaratorId.name;
if (declaratorInit!.type === "MemberExpression") {
if (declaratorInit?.type === "MemberExpression") {
importSpecifiers.add({
importedName: (declaratorInit.property as Identifier).name,
localName: declaratorIdName,
Expand All @@ -48,7 +48,7 @@ export const getImportSpecifiers = (
}

if (declaratorId.type === "ObjectPattern") {
if (declaratorInit!.type !== "CallExpression") {
if (declaratorInit?.type !== "CallExpression") {
continue;
}
const properties = declaratorId.properties as (Property | ObjectProperty)[];
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/v2-to-v3/ts-type/getClientTypeNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getClientTypeNames = (
clientTypeNames.push(
...getImportSpecifiers(j, source, getClientDeepImportPath(v2ClientName))
.filter((importSpecifier) => importSpecifier.importedName)
.map((importSpecifier) => (importSpecifier as ImportSpecifierType).localName!)
.map((importSpecifier) => (importSpecifier as ImportSpecifierType).localName)
);

return [...new Set(clientTypeNames)];
Expand Down

0 comments on commit bf76ad1

Please sign in to comment.