question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tslint trying to lint JSON

See original GitHub issue

I’m trying to use the new JSON imports in TypeScript 2.9. I’m using a simple import for a JSON file:

import cfg from 'operations_client_config.json';

It builds great, but is failing at lint time with an error. Not sure why tslint is all of the sudden deciding that it should import the JSON file and lint it as TypeScript 🤷‍♂️

> google-gax@0.16.1 check /Users/beckwith/Code/gax-nodejs
> gts check

The 'no-reference' rule threw an error in '/Users/beckwith/Code/gax-nodejs/src/operations_client_config.json':
TypeError: Cannot read property 'length' of undefined
    at walk (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/rules/noReferenceRule.js:46:67)
    at Rule.AbstractRule.applyWithFunction (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/language/rule/abstractRule.js:39:9)
    at Rule.apply (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/rules/noReferenceRule.js:27:21)
    at Linter.applyRule (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/linter.js:197:29)
    at /Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/linter.js:139:85
    at Object.flatMap (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/utils.js:151:29)
    at Linter.getAllFailures (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/linter.js:139:32)
    at Linter.lint (/Users/beckwith/Code/gax-nodejs/node_modules/tslint/lib/linter.js:99:33)
    at srcFiles.forEach.file (/Users/beckwith/Code/gax-nodejs/node_modules/gts/build/src/lint.js:43:20)
    at Array.forEach (<anonymous>)
/Users/beckwith/Code/gax-nodejs/src/operations_client_config.json
unused expression, expected an assignment or function call (no-unused-expression)
> 1 | {
  2 |   "interfaces": {
  3 |     "google.longrunning.Operations": {
  4 |       "retry_codes": {

Missing semicolon (semicolon)
  44 |     }
  45 |   }
> 46 | }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

33reactions
GabrielDelepinecommented, Oct 26, 2018

Please add in your tslint.json file

{
  "linterOptions": {
    "exclude": [
      "*.json",
      "**/*.json"
    ]
  }
}

**/*.json is necessary to be recursive

Available since version 5.8

3reactions
focuxcommented, Feb 15, 2019

It worked like a charm! Thanks @GabrielDelepine!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring TSLint - Palantir Open Source
When using the CLI or many third-party tools, a file named tslint.json or tslint.yaml is used to configure which rules get run and...
Read more >
TSLint command-line interface - Palantir Open Source
By default, TSLint looks for a configuration file named tslint.json in the directory of the file being linted and, if not found, searches...
Read more >
Testing Rules
The test system lints the .ts.lint files with the settings specified in tslint.json and makes sure that failures generated by the TSLint match...
Read more >
TSLint core rules - Palantir Open Source
Lint rules encode logic for syntactic & semantic checks of TypeScript source code. TypeScript-specific. These rules find errors related to TypeScript features:.
Read more >
TSLint - Palantir Open Source
A linter for the TypeScript language. ... a basic configuration file tslint --init # Lint TypeScript source globs tslint -c tslint.json 'src/**/*.ts'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found