Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gentype: suppress lints from generated files #6442

Merged
merged 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# 11.0.0-rc.5 (Unreleased)

#### :boom: Breaking Change

- Gentype now emits comments to suppress warnings from [`@typescript-eslint/plugin`](https://typescript-eslint.io/) instead of TSLint. https://github.com/rescript-lang/rescript-compiler/pull/6442

#### :bug: Bug Fix

- Fix issue with dynamic import of module in nested expressions https://github.com/rescript-lang/rescript-compiler/pull/6431
Expand Down
25 changes: 12 additions & 13 deletions jscomp/gentype/EmitType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
in
let tagField =
case |> labelJSToString
|> field
~name:(Runtime.jsVariantTag ~polymorphic:false ~tag)
|> field ~name:(Runtime.jsVariantTag ~polymorphic:false ~tag)
in
match (unboxed, type_) with
| true, type_ ->
Expand Down Expand Up @@ -355,20 +354,18 @@ let emitExportType ~(config : Config.t) ~emitters ~nameAs ~opaque ~type_
| true -> "any"
| false -> typeVars |> String.concat " | "
in
"// tslint:disable-next-line:max-classes-per-file \n"
^ (match String.capitalize_ascii resolvedTypeName <> resolvedTypeName with
| true -> "// tslint:disable-next-line:class-name\n"
| false -> "")
"// eslint-disable-next-line max-classes-per-file naming-convention\n"
^ docString ^ "export abstract class " ^ resolvedTypeName ^ typeParamsString
^ " { protected opaque!: " ^ typeOfOpaqueField
^ " }; /* simulate opaque types */" ^ exportNameAs
|> Emitters.export ~emitters
else
(if isInterface && config.exportInterfaces then
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString ^ " "
else
"// tslint:disable-next-line:interface-over-type-literal\n" ^ docString
^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
"// eslint-disable-next-line consistent-type-definitions\n"
^ (if isInterface && config.exportInterfaces then
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString
^ " "
else
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
^ (match type_ with
| _ -> type_ |> typeToString ~config ~typeNameIsInterface)
^ ";" ^ exportNameAs
Expand All @@ -388,8 +385,10 @@ let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
~moduleName importPath =
let commentBeforeRequire =
match importedValueOrComponent with
| true -> "// tslint:disable-next-line:no-var-requires\n"
| false -> "// @ts-ignore: Implicit any on import\n"
| true -> "// eslint-disable-next-line @typescript-eslint/no-var-requires\n"
| false ->
"// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n"
^ "// @ts-ignore: Implicit any on import\n"
in
let importPath =
match config.moduleResolution with
Expand Down
6 changes: 4 additions & 2 deletions jscomp/gentype_tests/typescript-react-example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"extends": [
"react-app",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"ignorePatterns": ["src/**/*.bs.js", "src/**/*.tsx", "src/MyMath.ts"]
}
"ignorePatterns": ["src/**/*.bs.js", "src/**/*.tsx", "src/MyMath.ts"],
"root": true
}
Loading