Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

export-name: export declarations are not flagged #444

Closed
amacleay opened this issue Jun 20, 2018 · 1 comment
Closed

export-name: export declarations are not flagged #444

amacleay opened this issue Jun 20, 2018 · 1 comment
Labels
Difficulty: Medium People with non-trivial experience in TSLint should be able to send a pull request for this issue. Resolution: Fixed Hooray! Type: Breaking Change Type: Bug
Milestone

Comments

@amacleay
Copy link
Contributor

Suppose I have a file named passLint.ts:

// $ cat src/failLint.ts
export function fish() : string {
  return '🐟';
}

The export-name rule will rightly complain that the export name does not match.

Suppose that, instead, I write the export on a different line from the function declaration:

// $ cat src/passLint.ts
function fish() : string {
  return '🐟';
}
export { fish }

export-name fails to fire on this, even though it results in identical javascript output:

// $ tsc; cat src/failLint.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function fish() {
    return '🐟';
}
exports.fish = fish;

// $ diff src/*.js  # produces no output because files match

All source code for a minimal example:

$ for x in $( git ls-files | grep -v yarn ); do echo;echo "# $x"; cat $x; done

# .gitignore
node_modules
yarn-error.log

# package.json
{
  "name": "tmp.xj0vgsu2jj",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "lint": "tslint --format stylish --project ."
  },
  "author": "",
  "license": "UNLICENCED",
  "devDependencies": {
    "tslint": "^5.10.0",
    "tslint-microsoft-contrib": "^5.0.3",
    "typescript": "2.9.2"
  }
}

# src/failLint.ts
export function fish() : string {
  return '🐟';
}

# src/passLint.ts
function fish() : string {
  return '🐟';
}
export { fish };

# tsconfig.json
{
  "compilerOptions": {
    /* Basic Options */
    "target": "ES5",
    "lib": [ // Specify library files to be included in the compilation.
      "es2015",
      "es2017"
    ],

    /* Strict Type-Checking Options */
    "strict": true, // Enable all strict type-checking options.
    "strictNullChecks": true, // Enable strict null checks.

    /* Additional Checks */
    "noUnusedLocals": true, // Report errors on unused locals.
    "noUnusedParameters": true, // Report errors on unused parameters.
    "noImplicitReturns": true, // Report error when not all code paths in function return a value.
    "noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement.

    /* Module Resolution Options */
    "moduleResolution": "node", // Specify module resolution strategy.
    "allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
    "esModuleInterop": true, // Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports.
  },
  "exclude": ["node_modules/"]
}

# tslint.yml
extends:
  - tslint-microsoft-contrib # https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/recommended_ruleset.js
rules:
  missing-jsdoc: false
@JoshuaKGoldberg
Copy link

Unrelated: for x in $( git ls-files | grep -v yarn ); do echo;echo "# $x"; cat $x; done is nifty. Thanks for that! ✨

@JoshuaKGoldberg JoshuaKGoldberg added Type: Bug Status: Accepting PRs Difficulty: Medium People with non-trivial experience in TSLint should be able to send a pull request for this issue. labels Jul 4, 2018
@JoshuaKGoldberg JoshuaKGoldberg added this to the 5.0.4 milestone Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Medium People with non-trivial experience in TSLint should be able to send a pull request for this issue. Resolution: Fixed Hooray! Type: Breaking Change Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants