@nivinjoseph/n-strument 1.0.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.yarnrc.yml CHANGED
@@ -1,3 +1,10 @@
1
+ approvedGitRepositories:
2
+ - "**"
3
+
4
+ enableScripts: false
5
+
1
6
  nodeLinker: node-modules
2
7
 
3
- yarnPath: .yarn/releases/yarn-4.4.1.cjs
8
+ npmMinimalAgeGate: 0
9
+
10
+ yarnPath: .yarn/releases/yarn-4.16.0.cjs
package/README.md CHANGED
@@ -1,2 +1,118 @@
1
1
  # n-strument
2
- Instrumentation helper library
2
+
3
+ Instrumentation helper library.
4
+
5
+ A zero-config-code bootstrap for [OpenTelemetry](https://opentelemetry.io/) distributed tracing in Node.js apps. Importing it wires up auto-instrumentation and an OTLP exporter for you — there is no API to call.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @nivinjoseph/n-strument
11
+ # or
12
+ yarn add @nivinjoseph/n-strument
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ This is primarily a **side-effect-on-import module**: importing it sets up auto-instrumentation and the OTLP exporter. It also exports a single `shutdownTracing` function for draining spans on shutdown (see below). Import it once, as the **very first import** in your application's entry point, before any module you want traced is loaded:
18
+
19
+ ```ts
20
+ // main.ts — the FIRST import, before koa/pg/redis/aws-sdk/etc.
21
+ import "@nivinjoseph/n-strument";
22
+
23
+ // ...the rest of your app
24
+ import { startServer } from "./server.js";
25
+ startServer();
26
+ ```
27
+
28
+ Order matters: OpenTelemetry auto-instrumentation patches modules at load time, so anything imported before `n-strument` will not be traced. For a guaranteed-first load you can preload it via Node instead:
29
+
30
+ ```bash
31
+ node --import @nivinjoseph/n-strument ./dist/main.js
32
+ ```
33
+
34
+ n-strument does not expose an API for creating custom spans. It sets up the global tracer provider, so use [`@opentelemetry/api`](https://www.npmjs.com/package/@opentelemetry/api) directly for manual instrumentation:
35
+
36
+ ```ts
37
+ import { trace } from "@opentelemetry/api";
38
+
39
+ const tracer = trace.getTracer("my-service");
40
+ const span = tracer.startSpan("do-work");
41
+ // ...
42
+ span.end();
43
+ ```
44
+
45
+ ### Graceful shutdown
46
+
47
+ Spans are buffered in memory by a `BatchSpanProcessor` and flushed periodically. On process exit that buffer is **not** drained automatically, so the spans around a deploy, scale-down, or shutdown — often the ones you most want — can be lost. n-strument does **not** register its own `SIGTERM`/`SIGINT` handlers (that would race with, and prematurely exit out of, your service's shutdown). Instead it exports `shutdownTracing`, which you call as the **last** step of your own graceful-shutdown sequence — after you've stopped accepting work and finished in-flight requests, so their spans are captured:
48
+
49
+ ```ts
50
+ import { shutdownTracing } from "@nivinjoseph/n-strument";
51
+
52
+ async function onShutdown(): Promise<void>
53
+ {
54
+ await server.stop(); // stop accepting traffic, drain in-flight requests
55
+ await db.dispose(); // your other cleanup
56
+ await shutdownTracing(); // flush + shut down the exporter, last
57
+ }
58
+ ```
59
+
60
+ `shutdownTracing()` flushes the buffer and shuts the exporter down. It is idempotent — repeat calls return the same shutdown — so it's safe to wire into multiple paths.
61
+
62
+ This works with the `node --import` style too: ES modules are singletons, so importing `shutdownTracing` from your code returns the same instance that `--import` already loaded, operating on the same tracer provider.
63
+
64
+ ## Configuration
65
+
66
+ All settings are read through [`@nivinjoseph/n-config`](https://www.npmjs.com/package/@nivinjoseph/n-config)'s `ConfigurationManager` (environment variables / config files).
67
+
68
+ | Config key | Required | Default | Purpose |
69
+ | ----------------------------------- | -------- | -------------------------------------- | ------------------------------------------------------------------- |
70
+ | `env` | **Yes** | — | App environment. Throws on startup if missing. `"dev"` defaults the trace host to `localhost`. |
71
+ | `package_name` (or `package.name`) | No | — | Sets the `service.name` resource attribute. |
72
+ | `package.version` | No | — | Sets the `service.version` resource attribute. |
73
+ | `otelTraceSamplingRate` | No | `1` (100%) | Parent-based ratio sampler. |
74
+ | `enableXrayTracing` | No | `false` | Use the AWS X-Ray ID generator + propagator. |
75
+ | `otelTraceHost` | No | `localhost` (dev) / `0.0.0.0` (other) | Host of the OTLP collector. |
76
+
77
+ > ⚠️ If `env` is not set, importing the module throws immediately:
78
+ > `ApplicationException: Required config 'env' not found`.
79
+
80
+ ## Backend / infrastructure
81
+
82
+ Spans are exported over **OTLP/HTTP** to `http://<otelTraceHost>:4318/v1/traces`. You need an OpenTelemetry Collector — or any OTLP-HTTP-compatible backend (Jaeger, Grafana Tempo, AWS Distro for OpenTelemetry, etc.) — listening on port **4318**. Without one, the app still runs but span exports fail in the background.
83
+
84
+ ### Minimal local setup
85
+
86
+ ```bash
87
+ # configuration (env vars, or however your n-config is wired)
88
+ export env=dev
89
+ export package_name=my-service
90
+ export package.version=1.0.0
91
+
92
+ # run a collector on :4318
93
+ docker run -p 4318:4318 otel/opentelemetry-collector
94
+ ```
95
+
96
+ ## What gets instrumented
97
+
98
+ The following auto-instrumentations are enabled. This set is fixed and not configurable without editing the library — but the full list of instrumentations is declared explicitly in `src/index.ts`, so flipping one on or off is a one-line `enabled` change:
99
+
100
+ - HTTP
101
+ - gRPC
102
+ - PostgreSQL (`pg`)
103
+ - Knex
104
+ - Redis / ioredis
105
+ - Koa (middleware-layer spans are suppressed)
106
+ - AMQP / RabbitMQ (`amqplib`)
107
+ - Kafka (`kafkajs`)
108
+ - Socket.IO
109
+ - AWS SDK
110
+ - AWS Lambda
111
+
112
+ Every other instrumentation that `@opentelemetry/auto-instrumentations-node` ships (Express, Hapi, NestJS, MongoDB, MySQL, GraphQL, DNS, `fs`, the logging integrations, etc.) is explicitly disabled.
113
+
114
+ To change the set, edit the `instrumentationConfig` map in [`src/index.ts`](src/index.ts) — it lists every instrumentation the library knows about with an explicit `enabled` flag, so toggling one is a single `true`/`false` edit. The map is typed `Required<InstrumentationConfigMap>`, which means a future `@opentelemetry/auto-instrumentations-node` upgrade that adds a new instrumentation will fail the build until you add the key and make a deliberate enabled/disabled decision (rather than letting it silently default to on).
115
+
116
+ ## License
117
+
118
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,2 +1,10 @@
1
- export {};
1
+ /**
2
+ * Flushes any buffered spans and shuts the tracer exporter down.
3
+ *
4
+ * Call this from your service's graceful-shutdown sequence — after it has stopped accepting work
5
+ * and finished in-flight requests, so their spans are captured — to avoid losing the spans the
6
+ * BatchSpanProcessor is still holding in memory. Safe to call more than once: repeat calls return
7
+ * the same in-flight (or completed) shutdown.
8
+ */
9
+ export declare function shutdownTracing(): Promise<void>;
2
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+IA;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAW/C"}
package/dist/index.js CHANGED
@@ -1,44 +1,89 @@
1
1
  import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
2
- import { Resource } from "@opentelemetry/resources";
2
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
3
+ import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
4
+ import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
5
+ import { defaultResource, resourceFromAttributes } from "@opentelemetry/resources";
3
6
  import {
4
7
  // SemanticResourceAttributes,
5
8
  ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
6
9
  import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
7
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
8
10
  import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
9
- import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
10
11
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
11
12
  import { ConfigurationManager } from "@nivinjoseph/n-config";
12
- import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
13
13
  import { TypeHelper } from "@nivinjoseph/n-util";
14
14
  import { AWSXRayPropagator } from "@opentelemetry/propagator-aws-xray";
15
15
  import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
16
16
  // For troubleshooting, set the log level to DiagLogLevel.DEBUG
17
17
  diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
18
+ // Every key in the InstrumentationConfigMap is listed explicitly with an `enabled` flag. The
19
+ // config object is an *override map*, not an allow-list: any instrumentation left out (or set to
20
+ // `undefined`) runs at its own default, which for this library version means ~39 of 40 are on.
21
+ // Listing all of them makes the enabled set unambiguous and makes a future library version that
22
+ // adds a new instrumentation conspicuous by its absence here, instead of silently turning on.
23
+ //
24
+ // Enabled: http, grpc, pg, knex, redis, ioredis, koa, amqplib, kafkajs, socket.io, aws-sdk,
25
+ // aws-lambda. Everything else off.
26
+ // Entries are kept in the library's own InstrumentationMap order for easy auditing on upgrade.
27
+ // `Required<...>` strips the optional modifier off every key, so this literal must list every
28
+ // instrumentation the library knows about. When an OTel upgrade adds a new one, the missing key
29
+ // becomes a compile error here — forcing a deliberate enabled/disabled decision rather than a
30
+ // silent default-on.
31
+ const instrumentationConfig = {
32
+ "@opentelemetry/instrumentation-amqplib": { enabled: true },
33
+ "@opentelemetry/instrumentation-aws-lambda": { enabled: true },
34
+ "@opentelemetry/instrumentation-aws-sdk": { enabled: true },
35
+ "@opentelemetry/instrumentation-bunyan": { enabled: false },
36
+ "@opentelemetry/instrumentation-cassandra-driver": { enabled: false },
37
+ "@opentelemetry/instrumentation-connect": { enabled: false },
38
+ "@opentelemetry/instrumentation-cucumber": { enabled: false },
39
+ "@opentelemetry/instrumentation-dataloader": { enabled: false },
40
+ "@opentelemetry/instrumentation-dns": { enabled: false },
41
+ "@opentelemetry/instrumentation-express": { enabled: false },
42
+ "@opentelemetry/instrumentation-fs": { enabled: false },
43
+ "@opentelemetry/instrumentation-generic-pool": { enabled: false },
44
+ "@opentelemetry/instrumentation-graphql": { enabled: false },
45
+ "@opentelemetry/instrumentation-grpc": { enabled: true },
46
+ "@opentelemetry/instrumentation-hapi": { enabled: false },
47
+ "@opentelemetry/instrumentation-http": { enabled: true },
48
+ "@opentelemetry/instrumentation-ioredis": { enabled: true },
49
+ "@opentelemetry/instrumentation-kafkajs": { enabled: true },
50
+ "@opentelemetry/instrumentation-knex": { enabled: true },
51
+ "@opentelemetry/instrumentation-koa": { enabled: true, ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
52
+ "@opentelemetry/instrumentation-lru-memoizer": { enabled: false },
53
+ "@opentelemetry/instrumentation-memcached": { enabled: false },
54
+ "@opentelemetry/instrumentation-mongodb": { enabled: false },
55
+ "@opentelemetry/instrumentation-mongoose": { enabled: false },
56
+ "@opentelemetry/instrumentation-mysql2": { enabled: false },
57
+ "@opentelemetry/instrumentation-mysql": { enabled: false },
58
+ "@opentelemetry/instrumentation-nestjs-core": { enabled: false },
59
+ "@opentelemetry/instrumentation-net": { enabled: false },
60
+ "@opentelemetry/instrumentation-openai": { enabled: false },
61
+ "@opentelemetry/instrumentation-oracledb": { enabled: false },
62
+ "@opentelemetry/instrumentation-pg": { enabled: true },
63
+ "@opentelemetry/instrumentation-pino": { enabled: false },
64
+ "@opentelemetry/instrumentation-redis": { enabled: true },
65
+ "@opentelemetry/instrumentation-restify": { enabled: false },
66
+ "@opentelemetry/instrumentation-router": { enabled: false },
67
+ "@opentelemetry/instrumentation-runtime-node": { enabled: false },
68
+ "@opentelemetry/instrumentation-socket.io": { enabled: true },
69
+ "@opentelemetry/instrumentation-tedious": { enabled: false },
70
+ "@opentelemetry/instrumentation-undici": { enabled: false },
71
+ "@opentelemetry/instrumentation-winston": { enabled: false }
72
+ };
18
73
  // This registers all instrumentation packages
19
74
  registerInstrumentations({
20
75
  instrumentations: [
21
- getNodeAutoInstrumentations({
22
- "@opentelemetry/instrumentation-http": undefined,
23
- "@opentelemetry/instrumentation-grpc": undefined,
24
- "@opentelemetry/instrumentation-redis": undefined,
25
- "@opentelemetry/instrumentation-ioredis": undefined,
26
- "@opentelemetry/instrumentation-pg": undefined,
27
- "@opentelemetry/instrumentation-knex": undefined,
28
- "@opentelemetry/instrumentation-koa": { ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
29
- "@opentelemetry/instrumentation-aws-sdk": undefined,
30
- "@opentelemetry/instrumentation-aws-lambda": undefined
31
- })
76
+ getNodeAutoInstrumentations(instrumentationConfig)
32
77
  ]
33
78
  });
34
79
  const env = ConfigurationManager.requireStringConfig("env");
35
80
  const isDev = env === "dev";
36
- const resource = Resource.default().merge(new Resource({
81
+ const resource = defaultResource().merge(resourceFromAttributes({
37
82
  // [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
38
83
  // [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
39
84
  // [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
40
- [ATTR_SERVICE_NAME]: ConfigurationManager.getConfig("package_name") ?? ConfigurationManager.getConfig("package.name"),
41
- [ATTR_SERVICE_VERSION]: ConfigurationManager.getConfig("package.version")
85
+ [ATTR_SERVICE_NAME]: ConfigurationManager.getConfig("package_name") ?? ConfigurationManager.getConfig("package.name") ?? undefined,
86
+ [ATTR_SERVICE_VERSION]: ConfigurationManager.getConfig("package.version") ?? undefined
42
87
  }));
43
88
  const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
44
89
  const enableXrayTracing = TypeHelper.parseBoolean(ConfigurationManager.getConfig("enableXrayTracing")) ?? false;
@@ -51,7 +96,6 @@ if (enableXrayTracing)
51
96
  let traceHost = ConfigurationManager.getConfig("otelTraceHost");
52
97
  if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
53
98
  traceHost = isDev ? "localhost" : "0.0.0.0";
54
- const provider = new NodeTracerProvider();
55
99
  // const exporter = new ConsoleSpanExporter();
56
100
  const exporter = new OTLPTraceExporter({
57
101
  // optional - default url is http://localhost:4318/v1/traces
@@ -60,6 +104,33 @@ const exporter = new OTLPTraceExporter({
60
104
  headers: {}
61
105
  });
62
106
  const processor = new BatchSpanProcessor(exporter);
63
- provider.addSpanProcessor(processor);
107
+ // Span processors are now supplied via the constructor (addSpanProcessor was removed in the OTel SDK 2.x line).
108
+ const provider = new NodeTracerProvider({
109
+ ...tracerConfig,
110
+ spanProcessors: [processor]
111
+ });
64
112
  provider.register(enableXrayTracing ? { propagator: new AWSXRayPropagator() } : undefined);
113
+ // The BatchSpanProcessor buffers finished spans in memory and only flushes periodically (or once a
114
+ // batch fills); its flush timer is unref'd, so the process can exit with spans still buffered, and
115
+ // the Node processor registers no exit handlers of its own. Rather than have this library grab
116
+ // SIGTERM/SIGINT — which would race with, and process.exit() out of, the host service's own
117
+ // graceful-shutdown sequence — we export a drain function for the host to invoke as part of its
118
+ // shutdown. provider.shutdown() flushes the buffer and shuts the exporter down.
119
+ let shutdownPromise = null;
120
+ /**
121
+ * Flushes any buffered spans and shuts the tracer exporter down.
122
+ *
123
+ * Call this from your service's graceful-shutdown sequence — after it has stopped accepting work
124
+ * and finished in-flight requests, so their spans are captured — to avoid losing the spans the
125
+ * BatchSpanProcessor is still holding in memory. Safe to call more than once: repeat calls return
126
+ * the same in-flight (or completed) shutdown.
127
+ */
128
+ export function shutdownTracing() {
129
+ if (shutdownPromise != null)
130
+ return shutdownPromise;
131
+ shutdownPromise = provider.shutdown().catch((e) => {
132
+ diag.error("Error shutting down tracer provider", e);
133
+ });
134
+ return shutdownPromise;
135
+ }
65
136
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OACI;AACI,8BAA8B;AAC9B,iBAAiB,EAAE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8C;AAC9C,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC;IACnC,4DAA4D;IAE5D,GAAG,EAAE,UAAU,SAAS,iBAAiB;IACzC,yFAAyF;IACzF,OAAO,EAAE,EAAE;CACd,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AAEnD,gHAAgH;AAChH,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC;IACpC,GAAG,YAAY;IACf,cAAc,EAAE,CAAC,SAAS,CAAC;CAC9B,CAAC,CAAC;AAEH,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE3F,mGAAmG;AACnG,mGAAmG;AACnG,+FAA+F;AAC/F,4FAA4F;AAC5F,gGAAgG;AAChG,gFAAgF;AAChF,IAAI,eAAe,GAAyB,IAAI,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe;IAE3B,IAAI,eAAe,IAAI,IAAI;QACvB,OAAO,eAAe,CAAC;IAE3B,eAAe,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;QAEvD,IAAI,CAAC,KAAK,CAAC,qCAAqC,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AAC3B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "rootDir": "../src",
4
5
  "outDir": ".",
5
6
  "declaration": true,
6
7
  "declarationDir": ".",
@@ -0,0 +1,328 @@
1
+ import eslint from "@eslint/js";
2
+ import tsEslint from "typescript-eslint";
3
+ import { defineConfig } from "eslint/config";
4
+ import importPlugin from "eslint-plugin-import";
5
+ import tsParser from "@typescript-eslint/parser";
6
+
7
+ import stylistic from "@stylistic/eslint-plugin";
8
+
9
+ export default defineConfig(
10
+ eslint.configs.recommended,
11
+ tsEslint.configs.recommended,
12
+ importPlugin.flatConfigs.recommended,
13
+ {
14
+ ignores: ["dist/**", "node_modules/**", "**/*.js", "**/*.map", "**/*.d.ts"]
15
+ },
16
+ {
17
+ files: ["**/*.ts"],
18
+ extends: [importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.typescript],
19
+ languageOptions: {
20
+ parser: tsParser,
21
+ ecmaVersion: "latest",
22
+ sourceType: "module"
23
+ },
24
+ settings: {
25
+ "import/parsers": {
26
+ "@typescript-eslint/parser": [".ts", ".tsx"]
27
+ },
28
+ "import/resolver": {
29
+ node: {
30
+ extensions: [".js", ".jsx", ".ts", ".tsx"]
31
+ },
32
+ typescript: {
33
+ project: "./tsconfig.json"
34
+ }
35
+ },
36
+ },
37
+ rules: {
38
+ "import/no-extraneous-dependencies": ["error"]
39
+ }
40
+ },
41
+ {
42
+ files: ["**/*.ts"],
43
+ languageOptions: {
44
+ parserOptions: {
45
+ tsconfigRootDir: import.meta.dirname,
46
+ projectService: true
47
+ }
48
+ },
49
+ plugins: {
50
+ "@stylistic/ts": stylistic
51
+ },
52
+ "rules": {
53
+ "import/extensions": [
54
+ "error",
55
+ "always",
56
+ {
57
+ "ts": "never",
58
+ "js": "always"
59
+ }
60
+ ],
61
+ "quotes": [
62
+ "error",
63
+ "double",
64
+ {
65
+ "allowTemplateLiterals": true
66
+ }
67
+ ],
68
+ "no-eval": "error",
69
+ "no-void": "error",
70
+ "no-with": "error",
71
+ "@typescript-eslint/adjacent-overload-signatures": "error",
72
+ "@typescript-eslint/array-type": [
73
+ "error",
74
+ {
75
+ "default": "generic",
76
+ "readonly": "generic"
77
+ }
78
+ ],
79
+ "@typescript-eslint/await-thenable": "error",
80
+ "@typescript-eslint/ban-ts-comment": [
81
+ "error",
82
+ {
83
+ "ts-expect-error": "allow-with-description",
84
+ "ts-ignore": "allow-with-description",
85
+ "ts-nocheck": true,
86
+ "ts-check": true
87
+ }
88
+ ],
89
+ "@typescript-eslint/ban-tslint-comment": "error",
90
+ "@typescript-eslint/no-empty-object-type": "error",
91
+ "@typescript-eslint/no-unsafe-function-type": "error",
92
+ "@typescript-eslint/no-wrapper-object-types": "off",
93
+ "@typescript-eslint/no-restricted-types": [
94
+ "error",
95
+ {
96
+ "types": {
97
+ "String": {
98
+ "message": "Use string instead",
99
+ "fixWith": "string"
100
+ },
101
+ "Boolean": {
102
+ "message": "Use boolean instead",
103
+ "fixWith": "boolean"
104
+ },
105
+ "Number": {
106
+ "message": "Use number instead",
107
+ "fixWith": "number"
108
+ },
109
+ "Symbol": {
110
+ "message": "Use symbol instead",
111
+ "fixWith": "symbol"
112
+ }
113
+ }
114
+ }
115
+ ],
116
+ "brace-style": "off",
117
+ "@stylistic/ts/brace-style": [
118
+ "error",
119
+ "allman",
120
+ {
121
+ "allowSingleLine": true
122
+ }
123
+ ],
124
+ "@typescript-eslint/class-literal-property-style": [
125
+ "off",
126
+ "getters"
127
+ ],
128
+ "comma-dangle": "off",
129
+ "@stylistic/ts/comma-dangle": [
130
+ "error",
131
+ {
132
+ "arrays": "never",
133
+ "objects": "only-multiline",
134
+ "imports": "never",
135
+ "exports": "never",
136
+ "functions": "never",
137
+ "enums": "only-multiline"
138
+ }
139
+ ],
140
+ "default-param-last": "off",
141
+ "@typescript-eslint/default-param-last": "error",
142
+ "@typescript-eslint/explicit-function-return-type": [
143
+ "error",
144
+ {
145
+ "allowExpressions": true
146
+ }
147
+ ],
148
+ "@typescript-eslint/explicit-member-accessibility": "error",
149
+ "@typescript-eslint/explicit-module-boundary-types": "error",
150
+ "func-call-spacing": "off",
151
+ "@stylistic/ts/function-call-spacing": [
152
+ "error",
153
+ "never"
154
+ ],
155
+ "@stylistic/ts/member-delimiter-style": [
156
+ "error",
157
+ {
158
+ "multiline": {
159
+ "delimiter": "semi",
160
+ "requireLast": true
161
+ },
162
+ "singleline": {
163
+ "delimiter": "semi",
164
+ "requireLast": true
165
+ },
166
+ "multilineDetection": "brackets"
167
+ }
168
+ ],
169
+ "@typescript-eslint/member-ordering": [
170
+ "error",
171
+ {
172
+ "default": [
173
+ // Index signature
174
+ "signature",
175
+ // Fields
176
+ "private-static-field",
177
+ "protected-static-field",
178
+ "public-static-field",
179
+ "private-instance-field",
180
+ "protected-instance-field",
181
+ "public-instance-field",
182
+ // Getters / Setters
183
+ [
184
+ "private-static-get",
185
+ "private-static-set"
186
+ ],
187
+ [
188
+ "protected-static-get",
189
+ "protected-static-set"
190
+ ],
191
+ [
192
+ "public-static-get",
193
+ "public-static-set"
194
+ ],
195
+ [
196
+ "private-instance-get",
197
+ "private-instance-set"
198
+ ],
199
+ [
200
+ "protected-instance-get",
201
+ "protected-instance-set"
202
+ ],
203
+ [
204
+ "public-instance-get",
205
+ "public-instance-set"
206
+ ],
207
+ // Constructors
208
+ "public-constructor",
209
+ "protected-constructor",
210
+ "private-constructor",
211
+ // Methods
212
+ "public-static-method",
213
+ "protected-static-method",
214
+ "private-static-method",
215
+ "public-instance-method",
216
+ "protected-instance-method",
217
+ "private-instance-method"
218
+ ]
219
+ }
220
+ ],
221
+ "@typescript-eslint/method-signature-style": [
222
+ "error",
223
+ "method"
224
+ ],
225
+ "@typescript-eslint/naming-convention": [
226
+ "error",
227
+ {
228
+ "selector": "memberLike",
229
+ "modifiers": [
230
+ "private"
231
+ ],
232
+ "format": [
233
+ "camelCase"
234
+ ],
235
+ "leadingUnderscore": "require"
236
+ }
237
+ ],
238
+ "@typescript-eslint/no-confusing-non-null-assertion": "error",
239
+ "@typescript-eslint/no-confusing-void-expression": [
240
+ "error",
241
+ {
242
+ "ignoreArrowShorthand": true
243
+ }
244
+ ],
245
+ "no-dupe-class-members": "off",
246
+ "@typescript-eslint/no-dupe-class-members": "error",
247
+ "@typescript-eslint/no-duplicate-enum-values": "error",
248
+ "no-duplicate-imports": "error",
249
+ "no-empty-function": "off",
250
+ "@typescript-eslint/no-empty-function": [
251
+ "error",
252
+ {
253
+ "allow": [
254
+ "private-constructors"
255
+ ]
256
+ }
257
+ ],
258
+ "@typescript-eslint/no-explicit-any": "off",
259
+ "@typescript-eslint/no-extra-non-null-assertion": "error",
260
+ "no-extra-parens": "off",
261
+ "@stylistic/ts/no-extra-parens": [
262
+ "error",
263
+ "all",
264
+ {
265
+ "nestedBinaryExpressions": false
266
+ }
267
+ ],
268
+ "no-extra-semi": "off",
269
+ "@stylistic/ts/no-extra-semi": "error",
270
+ "@typescript-eslint/no-floating-promises": "error",
271
+ "@typescript-eslint/no-for-in-array": "error",
272
+ "no-implied-eval": "off",
273
+ "@typescript-eslint/no-implied-eval": "error",
274
+ "no-invalid-this": "off",
275
+ "@typescript-eslint/no-invalid-this": "error",
276
+ "@typescript-eslint/no-invalid-void-type": "error",
277
+ "no-loop-func": "off",
278
+ "@typescript-eslint/no-loop-func": "error",
279
+ "no-loss-of-precision": "off",
280
+ "@typescript-eslint/no-loss-of-precision": "error",
281
+ "@typescript-eslint/no-meaningless-void-operator": "error",
282
+ "@typescript-eslint/no-misused-new": "error",
283
+ "@typescript-eslint/no-misused-promises": "error",
284
+ "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
285
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
286
+ "@typescript-eslint/no-non-null-assertion": "off",
287
+ "no-redeclare": "off",
288
+ "@typescript-eslint/no-redeclare": "error",
289
+ "@typescript-eslint/no-this-alias": "error",
290
+ "no-throw-literal": "error",
291
+ "@typescript-eslint/no-unnecessary-condition": [
292
+ "error",
293
+ {
294
+ "allowConstantLoopConditions": true
295
+ }
296
+ ],
297
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
298
+ "@typescript-eslint/no-unnecessary-type-constraint": "error",
299
+ "@typescript-eslint/no-unsafe-call": "error",
300
+ "@typescript-eslint/no-unsafe-return": "error",
301
+ "no-unused-expressions": "off",
302
+ "@typescript-eslint/no-unused-expressions": "error",
303
+ "no-unused-vars": "off",
304
+ "@typescript-eslint/no-unused-vars": "off",
305
+ "no-use-before-define": "off",
306
+ "@typescript-eslint/no-use-before-define": "off",
307
+ "no-useless-constructor": "off",
308
+ "@typescript-eslint/no-useless-constructor": "error",
309
+ "@typescript-eslint/no-useless-empty-export": "error",
310
+ "@typescript-eslint/no-var-requires": "off",
311
+ "@typescript-eslint/parameter-properties": "error",
312
+ "@typescript-eslint/prefer-enum-initializers": "error",
313
+ "@typescript-eslint/prefer-includes": "error",
314
+ "@typescript-eslint/prefer-literal-enum-member": "error",
315
+ "@typescript-eslint/prefer-readonly": "error",
316
+ "@typescript-eslint/prefer-reduce-type-parameter": "error",
317
+ "@typescript-eslint/prefer-string-starts-ends-with": "error",
318
+ "@typescript-eslint/prefer-ts-expect-error": "error",
319
+ "@typescript-eslint/require-array-sort-compare": "error",
320
+ "no-return-await": "off",
321
+ "@typescript-eslint/return-await": "error",
322
+ "semi": "off",
323
+ "@stylistic/ts/semi": "error",
324
+ "@typescript-eslint/unbound-method": "error",
325
+ "@typescript-eslint/no-require-imports": "error"
326
+ }
327
+ }
328
+ );