@pinyin/tslint
TSLint rules
Last updated 4 months ago by pinyin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @pinyin/tslint 
SYNC missed versions from official npm registry.

tslint

Build Status

TSLint rules.

Should work for JavaScript projects, too.

Usage

Add this library to project

npm install --save-dev @pinyin/tslint tslint-language-service typescript tslint

Then, edit tsconfig.json to include:

{
  "compilerOptions": {
    "allowJs": true,
    "plugins": [
      {
        "name": "tslint-language-service",
        "mockTypeScriptVersion": true
      }
    ]
  }
}

If you are not using TypeScript, create a tsconfig.json file at the root of your project.

Edit tslint.json to include:

{
  "defaultSeverity": "error",
  "rules": {
    "only-import-from-index": true
  },
  "rulesDirectory": [
    "node_modules/@pinyin/tslint/js"
  ]
}

If you are not using TSLint, create a tslint.json file at the root of your project.

Enable TypeScript in your IDE. You should be able to write JavaScript/TypeScript like before, with some additional checks.

TSLint would start with TypeScript Language Service, so there's no need to enable TSLint in your IDE.

Rules

only-import-from-index

If a directory contains an index.js/index.ts file, files outside of the directory can only import from index.js/index.ts file. No import can "pass through" the index file.

For example, given the following file structure:

src/
    index.ts(content):
        export {a} from './public'
    public.ts:
        import {b} from './private' // ok
        export const a = b
    private.ts:
        export const b = 'b'
out.ts:
    import {a} from './src' // ok
    import {b} from './src/private.ts' // error
    import {a} from './src/public.ts' // error

out.ts can only import from ./src, any other import into src will be reported as Error.

Only imports with relevant path will be checked.

Current Tags

  • 0.0.10                                ...           latest (4 months ago)

10 Versions

  • 0.0.10                                ...           4 months ago
  • 0.0.9                                ...           4 months ago
  • 0.0.8                                ...           4 months ago
  • 0.0.7                                ...           4 months ago
  • 0.0.6                                ...           4 months ago
  • 0.0.5                                ...           4 months ago
  • 0.0.4                                ...           4 months ago
  • 0.0.3                                ...           4 months ago
  • 0.0.2                                ...           4 months ago
  • 0.0.1                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 20
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |