1

I am building a CDK library and have everything working, but am planning / iterating through some development and when I do not assign a variable to be used, the CDK will fail on build. I know is not best practice to do this, hence throws a test error, but for purposes of building / saving / testing, need to turn this on. I see in the Projen API docs, the tsconfig API has the noUnusedLocals option (see https://github.com/projen/projen/blob/main/API.md#projen-typescriptcompileroptions) but do not see an option for this in the projenrc.js file or other places. And, cannot directly edit the tsconfig* files since those are protected by projen build. Anyone able to find a way to set the NoUnusedLocals: false?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
NickH48226
  • 149
  • 1
  • 9

2 Answers2

0

Add /* tslint:disable:no-unused-variable */ just before the line that is giving the error.

What also works for some cases, you can name the parameter name starting with _. This will be exempt from the check. Use _myVariable instead of myvariable to remove this warning.

Lucasz
  • 1,150
  • 9
  • 19
0

You can put the part you like to update in the projen config.

If you want update noUnusedLocals to false you can put this snippet to the projen.ts file.

tsconfig: {
    compilerOptions: {
      noUnusedLocals: false,
    },
  },

The whole file can than look like this.

import { awscdk } from 'projen';
const project = new awscdk.AwsCdkTypeScriptApp({
  cdkVersion: '2.79.1',
  defaultReleaseBranch: 'main',
  name: 'test-cdk-nag',
  projenrcTs: true,

  deps: ['cdk-nag'], /* Runtime dependencies of this module. */
  // description: undefined,  /* The description is just a string that helps people understand the purpose of the package. */
  devDeps: [], /* Build dependencies for this module. */
  // packageName: undefined,  /* The "name" in package.json. */
  tsconfig: {
    compilerOptions: {
      noUnusedLocals: false,
    },
  },
});
project.synth();

The result of tsconfig.json and tsconfig.dev.json looks like this.

// ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
{
  "compilerOptions": {
    "alwaysStrict": true,
    "declaration": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "lib": [
      "es2019"
    ],
    "module": "CommonJS",
    "noEmitOnError": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": false,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "strict": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "stripInternal": true,
    "target": "ES2019"
  },
  "include": [
    ".projenrc.js",
    "src/**/*.ts",
    "test/**/*.ts",
    ".projenrc.ts",
    "projenrc/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Johannes Konings
  • 188
  • 2
  • 10