Skip to content

Commit bf76ad1

Browse files
authored
Remove non-null assertions using the ! postfix operator (#898)
1 parent a301bf9 commit bf76ad1

File tree

7 files changed

+11
-6
lines changed

7 files changed

+11
-6
lines changed

.changeset/quick-chefs-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Remove non-null assertions using the `!` postfix operator

biome.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
},
2323
"style": {
2424
"noNamespace": "error",
25-
"noNonNullAssertion": "off",
2625
"noUnusedTemplateLiteral": "off",
2726
"useConsistentArrayType": {
2827
"level": "error",

src/transforms/v2-to-v3/modules/getRequireDeclaratorsWithProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const getRequireDeclaratorsWithProperty = (
1818

1919
if (declaratorId.type === "Identifier") {
2020
const declaratorIdName = declaratorId.name;
21-
if (declaratorInit!.type === "MemberExpression") {
21+
if (declaratorInit?.type === "MemberExpression") {
2222
const importedName = (declaratorInit.property as Identifier).name;
2323
if (localName === declaratorIdName && identifierName === importedName) {
2424
return true;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const getDefaultName = (packageName: string) =>
2+
// biome-ignore lint/style/noNonNullAssertion: This is a valid assertion
23
["AWS", ...packageName.split("/").pop()!.split("-")].join("_");

src/transforms/v2-to-v3/modules/importModule/getImportSpecifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getImportSpecifiers = (
1717
const importedName = specifier.imported.name;
1818
importSpecifiers.add({
1919
importedName,
20-
localName: specifier.local!.name || importedName,
20+
localName: specifier.local?.name || importedName,
2121
});
2222
break;
2323
}

src/transforms/v2-to-v3/modules/requireModule/getImportSpecifiers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const getImportSpecifiers = (
3737

3838
if (declaratorId.type === "Identifier") {
3939
const declaratorIdName = declaratorId.name;
40-
if (declaratorInit!.type === "MemberExpression") {
40+
if (declaratorInit?.type === "MemberExpression") {
4141
importSpecifiers.add({
4242
importedName: (declaratorInit.property as Identifier).name,
4343
localName: declaratorIdName,
@@ -48,7 +48,7 @@ export const getImportSpecifiers = (
4848
}
4949

5050
if (declaratorId.type === "ObjectPattern") {
51-
if (declaratorInit!.type !== "CallExpression") {
51+
if (declaratorInit?.type !== "CallExpression") {
5252
continue;
5353
}
5454
const properties = declaratorId.properties as (Property | ObjectProperty)[];

src/transforms/v2-to-v3/ts-type/getClientTypeNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const getClientTypeNames = (
5858
clientTypeNames.push(
5959
...getImportSpecifiers(j, source, getClientDeepImportPath(v2ClientName))
6060
.filter((importSpecifier) => importSpecifier.importedName)
61-
.map((importSpecifier) => (importSpecifier as ImportSpecifierType).localName!)
61+
.map((importSpecifier) => (importSpecifier as ImportSpecifierType).localName)
6262
);
6363

6464
return [...new Set(clientTypeNames)];

0 commit comments

Comments
 (0)