Skip to content

Commit 362451b

Browse files
authored
chore: Enable eslint rule no-unnecessary-type-assertion (#15260)
1 parent f5b5220 commit 362451b

44 files changed

Lines changed: 143 additions & 148 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports = {
3535
{
3636
files: ["**/*.ts"],
3737
parser: "@typescript-eslint/parser",
38+
parserOptions: {
39+
project: "./tsconfig.json",
40+
},
3841
plugins: ["@typescript-eslint"],
3942
rules: {
4043
"no-unused-vars": "off",
@@ -61,6 +64,7 @@ module.exports = {
6164
allowNamedExports: true,
6265
},
6366
],
67+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
6468
},
6569
},
6670
{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"@rollup/plugin-node-resolve": "^13.3.0",
4040
"@rollup/plugin-replace": "^4.0.0",
4141
"@types/node": "^18.11.7",
42-
"@typescript-eslint/eslint-plugin": "^5.41.0",
43-
"@typescript-eslint/parser": "^5.41.0",
42+
"@typescript-eslint/eslint-plugin": "^5.46.0",
43+
"@typescript-eslint/parser": "^5.46.0",
4444
"babel-plugin-transform-charcodes": "^0.2.0",
4545
"c8": "^7.12.0",
4646
"chalk": "^5.0.0",

packages/babel-cli/src/babel/watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function updateExternalDependencies(
123123
}
124124

125125
function removeFileDependency(filename: string, dep: string) {
126-
const deps = depToFiles.get(dep) as Set<string>;
126+
const deps = depToFiles.get(dep);
127127
deps.delete(filename);
128128

129129
if (deps.size === 0) {

packages/babel-core/src/config/files/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function* findRelativeConfig(
226226
envName,
227227
caller,
228228
packageData.pkg?.dirname === loc
229-
? packageToBabelConfig(packageData.pkg as ConfigFile)
229+
? packageToBabelConfig(packageData.pkg)
230230
: null,
231231
);
232232
}

packages/babel-core/src/config/files/module-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function guessJSModuleType(filename: string): "cjs" | "mjs" | "unknown" {
5959
}
6060

6161
function loadCjsDefault(filepath: string, fallbackToTranspiledModule: boolean) {
62-
const module = endHiddenCallStack(require)(filepath) as any;
62+
const module = endHiddenCallStack(require)(filepath);
6363
return module?.__esModule
6464
? // TODO (Babel 8): Remove "module" and "undefined" fallback
6565
module.default || (fallbackToTranspiledModule ? module : undefined)

packages/babel-core/src/gensync-utils/async.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function maybeAsync<Args extends unknown[], Return>(
2828
): Gensync<Args, Return> {
2929
return gensync({
3030
sync(...args) {
31-
const result = fn.apply(this, args) as Return;
31+
const result = fn.apply(this, args);
3232
if (isThenable(result)) throw new Error(message);
3333
return result;
3434
},

packages/babel-core/src/transformation/normalize-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function* normalizeFile(
4545
}
4646

4747
if (options.cloneInputAst) {
48-
ast = cloneDeep(ast) as t.File;
48+
ast = cloneDeep(ast);
4949
}
5050
} else {
5151
// @ts-expect-error todo: use babel-types ast typings in Babel parser

packages/babel-helper-create-class-features-plugin/src/fields.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ const privateNameHandlerLoose: Handler<PrivateNameState> = {
487487
boundGet(member) {
488488
return t.callExpression(
489489
t.memberExpression(this.get(member), t.identifier("bind")),
490+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
490491
[t.cloneNode(member.node.object as t.Expression)],
491492
);
492493
},
@@ -1045,7 +1046,7 @@ export function buildFieldsInitNodes(
10451046
// We special-case the single expression case to avoid the iife, since
10461047
// it's common.
10471048
if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) {
1048-
staticNodes.push(blockBody[0] as t.ExpressionStatement);
1049+
staticNodes.push(blockBody[0]);
10491050
} else {
10501051
staticNodes.push(template.statement.ast`(() => { ${blockBody} })()`);
10511052
}

packages/babel-helper-create-class-features-plugin/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export function createClassFeaturePlugin({
190190
const privateNamesMap = buildPrivateNamesMap(props);
191191
const privateNamesNodes = buildPrivateNamesNodes(
192192
privateNamesMap,
193-
(privateFieldsAsProperties ?? loose) as boolean,
193+
privateFieldsAsProperties ?? loose,
194194
file,
195195
);
196196

@@ -230,9 +230,9 @@ export function createClassFeaturePlugin({
230230
props,
231231
privateNamesMap,
232232
file,
233-
(setPublicClassFields ?? loose) as boolean,
234-
(privateFieldsAsProperties ?? loose) as boolean,
235-
(constantSuper ?? loose) as boolean,
233+
setPublicClassFields ?? loose,
234+
privateFieldsAsProperties ?? loose,
235+
constantSuper ?? loose,
236236
innerBinding,
237237
));
238238
}
@@ -245,9 +245,9 @@ export function createClassFeaturePlugin({
245245
props,
246246
privateNamesMap,
247247
file,
248-
(setPublicClassFields ?? loose) as boolean,
249-
(privateFieldsAsProperties ?? loose) as boolean,
250-
(constantSuper ?? loose) as boolean,
248+
setPublicClassFields ?? loose,
249+
privateFieldsAsProperties ?? loose,
250+
constantSuper ?? loose,
251251
innerBinding,
252252
));
253253
}

packages/babel-helper-member-expression-to-functions/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ const handle = {
288288
"=",
289289
context,
290290
// object must not be Super when `context` is an identifier
291+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
291292
object as t.Expression,
292293
);
293294
}

0 commit comments

Comments
 (0)