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

Commit

Permalink
Fixes sort-on-save to properly ignore non-python files.
Browse files Browse the repository at this point in the history
Resolves #15.
  • Loading branch information
lexicalunit committed Sep 23, 2017
1 parent 2971261 commit 36b0277
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.
33 changes: 25 additions & 8 deletions index.js → lib/index.js
Expand Up @@ -40,14 +40,13 @@ function getPythonEnvironment () {
}

export default {
config: require('./lib/config.coffee').config,
config: require('./config.coffee').config,

activate () {
if (atom.inDevMode()) console.log('activate atom-isort')
require('atom-package-deps').install('atom-isort')
const Sorter = require('./lib/sorter')
const Sorter = require('./sorter')
this.sorter = new Sorter(getPythonEnvironment())
this.linter = null
this.handleEvents()
},

Expand All @@ -65,7 +64,10 @@ export default {
this.editorSubs.add(atom.workspace.observeTextEditors((textEditor) => {
if (sortOnSave) {
textEditor._isortSortOnWillSave =
textEditor.buffer.onWillSave(() => this.sorter.sortImports(textEditor, true))
textEditor.buffer.onWillSave(() => {
if (textEditor.getGrammar().scopeName !== 'source.python') return
this.sorter.sortImports(textEditor, true)
})
} else {
__guard__(textEditor._isortSortOnWillSave, x => x.dispose())
}
Expand All @@ -74,9 +76,25 @@ export default {
},

provideLinter () {
const Linter = require('./lib/linter')
if (!this.linter) this.linter = new Linter(this.sorter)
return this.linter
let getSorter = () => this.sorter
return {
name: 'isort',
scope: 'file',
lintsOnChange: false,
grammarScopes: ['source.python'],
async lint (textEditor) {
const sorted = getSorter().checkImports(textEditor)
if (sorted) return []
return [{
severity: 'warning',
location: {
file: textEditor.getPath(),
position: [[0, 0], [0, 0]]
},
excerpt: 'Imports not sorted'
}]
}
}
},

deactivate () {
Expand All @@ -90,7 +108,6 @@ export default {
__guard__(this.subs, x => x.dispose())
this.subs = null

this.linter = null
this.sorter = null
}
}
Expand Down
36 changes: 0 additions & 36 deletions lib/linter.js

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "atom-isort",
"main": "./index",
"main": "./lib/index",
"version": "2.5.0",
"description": "Organize python imports using isort",
"repository": "https://github.com/lexicalunit/atom-isort",
Expand All @@ -9,7 +9,7 @@
"atom": ">=1.4.0 <2.0.0"
},
"package-deps": [
"linter"
"linter:2.0.0"
],
"providedServices": {
"linter": {
Expand All @@ -19,17 +19,19 @@
}
},
"dependencies": {
"atom-package-deps": "^4.2.0"
"atom-linter": "^10.0.0",
"atom-package-deps": "^4.6.0"
},
"keywords": [
"python",
"style",
"isort",
"formatting",
"productivity"
"productivity",
"linter"
],
"devDependencies": {
"eslint": "^4.3.0",
"eslint": "^4.5.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1",
Expand Down

0 comments on commit 36b0277

Please sign in to comment.