Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule: Enforce specific order of 3rd party and internal imports #9

Open
3 tasks
benjamincharity opened this issue May 9, 2019 · 0 comments
Open
3 tasks
Labels
Focus: rule An item concerning existing or new rules Type: feature

Comments

@benjamincharity
Copy link
Contributor

benjamincharity commented May 9, 2019

Currently we have a organization format that is not enforced by the linter. It would be nice to have a linter rule that marked out-of-place imports as warnings within an IDE and organized imports when the linter was run with the --fix flag.

import { Foo } from '@some/3rd/party';
// line break
import { Bar } from './../bar';
// line break
// line break
// project code

Rule details:

  • Group 3rd party at top of file with no preceding line break
    • 3rd party import is
      • a relative URL containing node_modules
      • an @ path import not found in tsconfig
      • path beginning with ~
  • Enforce single line break
  • Group internal imports (defined by relative links or paths found in tsconfig)
    • Local import is determined by:
      • relative URL
      • exclude relative URLs containing node_modules in the path
      • path beginning with @ that matches a path in tsconfig.paths
  • Enforce 2 line breaks

Note: ordering within groups still enforced by TSLint.


  • Create rule
  • Make the rule fixable
  • Add rule to our default ruleset

Resources

It looks like Shopify created something like this: https://github.com/shopify-graveyard/tslint-config-shopify/pull/48/files

See https://blog.angularindepth.com/bending-tslint-to-your-needs-6ae0a51e633 for inspiration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus: rule An item concerning existing or new rules Type: feature
Projects
None yet
Development

No branches or pull requests

1 participant