Skip to content

Commit

Permalink
fixer: remove trailing lines after regrouping
Browse files Browse the repository at this point in the history
  • Loading branch information
slonoed committed May 15, 2019
1 parent 4ba57cc commit 80dae86
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@slonoed/jsref",
"description": "JavaScript refactoring language server",
"version": "1.0.7",
"version": "1.0.8",
"author": "Dmitry Manannikov <[email protected]> (https://slonoed.net/)",
"license": "WTFPL",
"repository": "https://github.com/slonoed/jsref",
Expand Down
37 changes: 36 additions & 1 deletion src/fixers/__tests__/specs/experimental-group-imports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,39 @@ import zlib from 'zlib'
import { Dict } from 'interfaces'
import { get } from 'lodash'

import { Something } from './constants'
import { Something } from './constants'
===
name: preserve next line
column: 1
---
import { get } from 'lodash'
import { Dict } from 'interfaces'
import { Something } from './constants'
import zlib from 'zlib'

const a = 1
---
import zlib from 'zlib'

import { Dict } from 'interfaces'
import { get } from 'lodash'

import { Something } from './constants'

const a = 1
===
name: no system
column: 1
---
import { get } from 'lodash'
import { Dict } from 'interfaces'
import { Something } from './constants'

const a = 1
---
import { Dict } from 'interfaces'
import { get } from 'lodash'

import { Something } from './constants'

const a = 1
26 changes: 11 additions & 15 deletions src/fixers/experimental-group-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const fixer: Fixer<Data> = {
}

return {
title: `Group imports`,
title: `Group and sort imports`,
data: null,
}
},
Expand All @@ -106,7 +106,7 @@ const fixer: Fixer<Data> = {
if (node.loc) {
const loc: Range.t = {
start: node.loc.start,
end: {line: node.loc.end.line, column: node.loc.end.column + 1},
end: {line: node.loc.end.line + 1, column: 0},
}
patches.push(Patch.del(loc))
}
Expand All @@ -125,19 +125,15 @@ const fixer: Fixer<Data> = {

patches.reverse()

patches.push(
Patch.insert(j, Position.create(1, 0), [
joinImports(j, systemImports),
'\n',
'\n',
joinImports(j, packageImports),
'\n',
'\n',
joinImports(j, sourceImports),
'\n',
'\n',
])
)
const newText = [
joinImports(j, systemImports),
joinImports(j, packageImports),
joinImports(j, sourceImports),
]
.filter(a => a)
.join('\n\n')

patches.push(Patch.insert(j, Position.create(1, 0), [newText, '\n']))

return patches
},
Expand Down
2 changes: 1 addition & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jsref",
"description": "JavaScript refactoring language server",
"version": "1.0.12",
"version": "1.0.13",
"publisher": "slonoed",
"author": "Dmitry Manannikov <[email protected]> (https://slonoed.net/)",
"license": "WTFPL",
Expand Down

0 comments on commit 80dae86

Please sign in to comment.