Tslint: TypeScript coding guidelines say to not prefix interface with I

Created on 30 Sep 2017  ·  15Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 3.15.1
  • __TypeScript version__: 2.5.3
  • __Running TSLint via__: (pick one) CLI

TypeScript code being linted

// code snippet
interface TypeConfig { }

Actual behavior

[tslint] interface name must start with a capitalized I (interface-name)

Microsoft suggests interface names to not be prefixed with an I - https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#names

Question

Most helpful comment

Nevermind, I figured it out:

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts"
    ]
  },
  "rules": {
    "interface-name" : [true, "never-prefix"]
  }
}

All 15 comments

Note that these are the guidelines for writing the typescript compiler itself. It's not meant to be a style guide for any other typescript project out there.
If you want to adopt this style guide for your projects, you can just change the rule's config in your tslint.json to "interface-name" : [true, "never"]

50 cent from a passer-by:
"interface-name" : [true, "never-prefix"] instead of
"interface-name" : [true, "never"]
🙌

rule docs

I tried turning off the "I" prefix by adding interface-name to the default tslint.json that's generated by Create React App. However, it doesn't seem to work. Maybe I'm putting it in the wrong location?

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts"
    ]
  },
  "interface-name" : [true, "never-prefix"]
}

Nevermind, I figured it out:

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts"
    ]
  },
  "rules": {
    "interface-name" : [true, "never-prefix"]
  }
}

For some reason "interface-name": [true, "never"] doesn't work for me. But "interface-name": false works fine

@vasilev-alex "interface-name": [true, "never-prefix"] empasis on never-prefix

I'm still getting "interface name must start with a capitalized I"

this is my tslint.json:

{
  "rules": {
    "interface-name": [
      true,
      "never-prefix"
    ]
  },
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts",
      "coverage/lcov-report/*.js"
    ]
  }
}

What am I doing wrong?

@offg777 Nothing obvious. Link to repo?

The config looks correct to me - are you sure theres nothing else overriding it? The rule is definitely working properly for me

@offg777

"interface name must start with a capitalized I"

From where do you get this error? From your IDE or when running a CLI?
And I don't know about the exact cascading rules of tslint, but have you tried putting the "rules" block underneath "extends"?

厉害

Does eslint support that already?

Setting

"rules": {
    "interface-name": [
      true,
      "never-prefix"
    ]
  },

results in
Configuration for rule "interface-name" is invalid

Maybe this rule exists for a reason? Should every interface have a meaningful name obviously different from an implementing class?

This is bloody annoying idea of forcing the rest of the world following your preferences _outside the your own project_. Obtrusion of your own naming conventions in programming tools is a bug of the product developer neural network ;)

Good thing TSLint is deprecated and this issue is no longer relevant, then! #4534

Was this page helpful?
0 / 5 - 0 ratings