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

Move build settings to user settings. Add js_lint_folder command. #11

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ nbproject
*.sublime-project
*.sublime-workspace
.tm_properties
package-metadata.json
*.pyc

# Dreamweaver added files
_notes
Expand Down
12 changes: 7 additions & 5 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[{
"id": "jslint",
"caption": "JSLint",
"command": "jslint"
}]
[
{
"id": "jslint",
"caption": "JSLint File",
"command": "js_lint_file"
}
]
5 changes: 0 additions & 5 deletions Default.sublime-commands

This file was deleted.

11 changes: 8 additions & 3 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[{
"keys": ["ctrl+l"], "command": "jslint"
}]
[
{
"keys": [
"ctrl+l"
],
"command": "js_lint_file"
}
]
90 changes: 79 additions & 11 deletions JSLint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,82 @@
import sublime, sublime_plugin, re
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import re
import os

class autoJSLint(sublime_plugin.EventListener):
def on_post_save(self, view):
settings = sublime.load_settings("JSLint.sublime-settings")
if re.search( settings.get( "filename_filter" ), view.file_name() ):
view.window().run_command( "build" )
EXEC_LINT = 'js_lint_exec'
LINT_FOLDER = 'js_lint_folder'
SETTINGS_FILE = 'JSLint.sublime-settings'


class JsLintFileCommand(sublime_plugin.WindowCommand):

def run(self):
self.window.run_command(EXEC_LINT, {
'files': [self.window.active_view().file_name()]
})


class JsLintContainingFolderCommand(sublime_plugin.WindowCommand):

def run(self):
self.window.run_command(LINT_FOLDER, {
'dirs': [os.path.abspath(os.path.join(self.window.active_view().file_name(), os.pardir))]
})


class JsLintFolderCommand(sublime_plugin.WindowCommand):

def run(self, dirs):
settings = sublime.load_settings(SETTINGS_FILE)
files_to_lint = []
filename_filter = settings.get('filename_filter')

for (dirpath, dirnames, filenames) in os.walk(dirs[0]):
for filename in filenames:
if re.search(filename_filter, filename):
files_to_lint.append(os.path.join(dirpath, filename))

self.window.run_command(EXEC_LINT, {
'files': files_to_lint
})

def is_visible(self, dirs):
return len(dirs) > 0


class JsLintExecCommand(sublime_plugin.WindowCommand):

def run(self, files=[]):
settings = sublime.load_settings(SETTINGS_FILE)
self.window.run_command('exec', {
'cmd':
settings.get('jslint', ['node', sublime.packages_path() + '/JSLint/node_modules/jslint/bin/jslint']) +
settings.get('options', []) +
files,
'line_regex': settings.get('line_regex', '.*// Line ([0-9]*), Pos ([0-9]*)$'),
'file_regex': settings.get('file_regex', '(^[^# ]+.*$)')
})


class JsLintOnSave(sublime_plugin.EventListener):

def on_post_save(self, view):
settings = sublime.load_settings(SETTINGS_FILE)
if settings.get('run_on_save', False) == False:
return
if re.search(settings.get('filename_filter'), view.file_name()):
view.window().run_command(EXEC_LINT, {
'files': [view.file_name()]
})


# Support calls to the old API of the JSLint package.

class JslintCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('set_build_system', {
'file': 'Packages/JSLint/JSLint.sublime-build'
})
self.window.run_command('build')

def run(self):
self.window.run_command(EXEC_LINT, {
'files': [self.window.active_view().file_name()]
})
27 changes: 0 additions & 27 deletions JSLint.sublime-build

This file was deleted.

10 changes: 10 additions & 0 deletions JSLint.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"caption": "JSLint: File",
"command": "js_lint_file"
},
{
"caption": "JSLint: Containing Folder",
"command": "js_lint_containing_folder"
}
]
54 changes: 53 additions & 1 deletion JSLint.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
{
"filename_filter": "(\\.js|\\.css|\\.html|\\.json|\\.sass|\\.less)$"
// an array of options to pass to jslint, e.g.
// ["--white", "--vars"] or maybe ["--indent", "2", "--node", "false"]
// see https://github.com/reid/node-jslint
// or http://www.jslint.com/lint.html#options.
"options" : [
// tolerate missing 'use strict' pragma
// do not use this pragma unless you know what you are doing.
"--sloppy",
// suggest an indent level of two spaces.
"--indent", "2",
// assume node.js to predefine node globals.
"--node",
// tolerate unfiltered for in
//"--forin",
// tolerate dangling _ in identifiers.
"--nomen",
// tolerate many var statements per function.
"--vars",
// tolerate ++ and --.
"--plusplus",
// tolerate stupidity.
"--stupid"
]

// if true, run jslint on save.
,"run_on_save" : true

// a regex string to determine whether jslint
// should be run on a file.
// if a match is found (i.e. re.search(filename_filter, filename)),
// the file will be linted.
,"filename_filter": "(\\.js|\\.css|\\.html|\\.json|\\.sass|\\.less)$"


// jslint command you want to run as an array of strings.
// E.g.: ["jslint"] or ["/usr/local/bin/jslint"] or ["node", "mylinter.js"]
// Default is
// * Linux: ["node", "~/.config/sublime-text-2/Packages/JSLint/node_modules/jslint/bin/jslint"]
// * Mac: ["node", "~/Library/Application Support/Sublime Text 2/Packages/JSLint/node_modules/jslint/bin/jslint"]
// * Windows: ["node", "%APPDATA%/Sublime Text 2/Packages/JSLint/node_modules/jslint/bin/jslint"]
// using node-jslint v0.1.9. https://github.com/reid/node-jslint/tree/v0.1.9

// ,"jslint" : ["jslint"]


// if your own personal choice of jslint has an output
// different from the standard which comes with this package,
// you may have to change line_regex and file_regex
// check http://docs.sublimetext.info/en/latest/reference/build_systems.html
// to find out how these regular expressions work. The defaults are:

// ,"line_regex" : ".*// Line ([0-9]*), Pos ([0-9]*)$"
// ,"file_regex" : "(^[^# ]+.*$)"
}
114 changes: 59 additions & 55 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
[
{
"caption": "Tools",
"mnemonic": "t",
"id": "tools",
"children": [
{
"id": "jslint",
"caption": "JSLint",
"command": "jslint"
}
]
},
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children": [
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
{
"id": "tools",
"children": [
{
"caption": "JSLint",
"children": [
{
"command": "open_file",
"args": {
"file": "${packages}/JSLint/JSLint.sublime-settings"
},
"caption": "Settings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/JSLint.sublime-settings"
},
"caption": "Settings – User"
},
{
"command": "open_file",
"args": {
"file": "${packages}/JSLint/JSLint.sublime-build"
},
"caption": "Advanced Build Settings"
},
{
"caption": "-"
}
]
}
{
"id": "jslint",
"caption": "JSLint",
"command": "js_lint_file"
}
]
}
]
}
]

},
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children": [
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children": [
{
"caption": "JSLint",
"children": [
{
"command": "open_file",
"args": {
"file": "${packages}/JSLint/JSLint.sublime-settings"
},
"caption": "Settings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/JSLint.sublime-settings"
},
"caption": "Settings – User"
},
{
"caption": "-"
},
{
"command": "open_file",
"args": {
"file": "${packages}/JSLint/Default.sublime-keymap"
},
"caption": "Key Bindings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Default ($platform).sublime-keymap"
},
"caption": "Key Bindings – User"
}
]
}
]
}
]
}
]
Loading