{"action":"created","issue":{"url":"https://api.github.com/repos/palantir/tslint/issues/4134","repository_url":"https://api.github.com/repos/palantir/tslint","labels_url":"https://api.github.com/repos/palantir/tslint/issues/4134/labels{/name}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/4134/comments","events_url":"https://api.github.com/repos/palantir/tslint/issues/4134/events","html_url":"https://github.com/palantir/tslint/pull/4134","id":354041529,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEwOTIwMTM5","number":4134,"title":"Ordered imports grouping","user":{"login":"abierbaum","id":397889,"node_id":"MDQ6VXNlcjM5Nzg4OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/397889?v=4","gravatar_id":"","url":"https://api.github.com/users/abierbaum","html_url":"https://github.com/abierbaum","followers_url":"https://api.github.com/users/abierbaum/followers","following_url":"https://api.github.com/users/abierbaum/following{/other_user}","gists_url":"https://api.github.com/users/abierbaum/gists{/gist_id}","starred_url":"https://api.github.com/users/abierbaum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abierbaum/subscriptions","organizations_url":"https://api.github.com/users/abierbaum/orgs","repos_url":"https://api.github.com/users/abierbaum/repos","events_url":"https://api.github.com/users/abierbaum/events{/privacy}","received_events_url":"https://api.github.com/users/abierbaum/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-08-25T20:34:13Z","updated_at":"2018-08-29T22:35:10Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/palantir/tslint/pulls/4134","html_url":"https://github.com/palantir/tslint/pull/4134","diff_url":"https://github.com/palantir/tslint/pull/4134.diff","patch_url":"https://github.com/palantir/tslint/pull/4134.patch"},"body":"#### PR checklist\r\n\r\n- [x] Addresses an existing issue: helps #3450, allows for flexibility to address other custom cases\r\n- [x] New enhancement\r\n  - [x] Includes tests\r\n- [x] Documentation update\r\n\r\n#### Overview of change:\r\n\r\nThis PR adds support for configuring custom groups with the ordered-import rule.\r\n\r\nPreviously the rule would only group into third-party, parent directories, and current directory.  This change allows for fully customizing the grouping but still keeps a default that provides exactly the same as was there previously.\r\n\r\nAn example configuration would be something like this:\r\n\r\n```\r\n\"rules\": {\r\n    \"ordered-imports\": [\r\n        true,\r\n        {\r\n            \"import-sources-order\": \"case-insensitive\",\r\n            \"named-imports-order\": \"case-insensitive\",\r\n            \"grouped-imports\": true,\r\n            \"groups\": [\r\n                { \"match\": \"^@(rxjs/angular)\", \"order\": 10 },\r\n                { \"match\": \"^app\", \"order\": 20 },\r\n                { \"name\": \"parent_dir\", \"match\": \"^[.][.]\", \"order\": 50 },\r\n                { \"name\": \"current dir\", \"match\": \"^[.]\", \"order\": 40 },\r\n                { \"match\": null, \"order\": 30 }\r\n            ]\r\n        }\r\n    ]\r\n}\r\n```\r\nThis would enforce an ordering where all rxjs and angular imports would come in first group sorted, then all application imports, then all additional third-party imports, then relative parent imports, and finally current directory imports.\r\n\r\nThis provides the flexibility to support just many use cases and can be adapted easily.  \r\n\r\nThere are other projects such as [vscode import-sorter ](https://marketplace.visualstudio.com/items?itemName=mike-co.import-sorter) and a few unsupported tslint extensions that try to address this issue but it seems like this is something that would best be handled by tslint since it can already reorder imports.\r\n\r\nOne of the goals of this change is to allow using the fixer to automatically reformat imports on the fly.  So for example when using vscode or another editor with tslint support the user could enable the fixer to be run upon file save and have tslint restructure all imports to meet the given team's conventions.\r\n\r\n#### Is there anything you'd like reviewers to focus on?\r\nI tried to add some solid test examples but I may have missed a corner case.  Please let me know if you see something I should check.\r\n\r\nI tried to keep the changes to a minimum, but I did refactor some of the existing code to make the grouping implementation a bit more clear and straight forward.  I also added some comments to clarify a few places in the code that tripped me up.  If you would like these stripped back out just let me know.\r\n\r\nNote: There are a number of code style changes that were made by prettier as part of the precommit hook that is now part of tslint.  (just so you know I didn't go try to change the original authors coding style :) )\r\n\r\n#### CHANGELOG.md entry:\r\n\r\n[enhancement] `ordered-imports` now supports a groups option to provide custom grouping rules.\r\n"},"comment":{"url":"https://api.github.com/repos/palantir/tslint/issues/comments/417129137","html_url":"https://github.com/palantir/tslint/pull/4134#issuecomment-417129137","issue_url":"https://api.github.com/repos/palantir/tslint/issues/4134","id":417129137,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzEyOTEzNw==","user":{"login":"giladgray","id":464822,"node_id":"MDQ6VXNlcjQ2NDgyMg==","avatar_url":"https://avatars1.githubusercontent.com/u/464822?v=4","gravatar_id":"","url":"https://api.github.com/users/giladgray","html_url":"https://github.com/giladgray","followers_url":"https://api.github.com/users/giladgray/followers","following_url":"https://api.github.com/users/giladgray/following{/other_user}","gists_url":"https://api.github.com/users/giladgray/gists{/gist_id}","starred_url":"https://api.github.com/users/giladgray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giladgray/subscriptions","organizations_url":"https://api.github.com/users/giladgray/orgs","repos_url":"https://api.github.com/users/giladgray/repos","events_url":"https://api.github.com/users/giladgray/events{/privacy}","received_events_url":"https://api.github.com/users/giladgray/received_events","type":"User","site_admin":false},"created_at":"2018-08-29T22:35:10Z","updated_at":"2018-08-29T22:35:10Z","author_association":"MEMBER","body":"destroying history shouldn't be part of your default workflow 😄 "}}
{"actor":{"display_login":"giladgray"}}