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

Commit

Permalink
Merge pull request #1 from AtomLinter/master
Browse files Browse the repository at this point in the history
Add option for linting inline JavaScript
  • Loading branch information
jacobmllr95 committed Jul 15, 2015
2 parents bfc6a16 + f555936 commit 5ce6cc3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ $ apm install linter-jshint

## Settings
You can configure linter-jshint by editing ~/.atom/config.cson (choose Open Your Config in Atom menu):
```
```coffee
'linter-jshint':
'jshintExecutablePath': null #jshint path. run 'which jshint' to find the path
jshintExecutablePath: (default: null) 'jsHint path. Run `which jshint` to find the path'
lintInlineJavaScript: (default: false) 'Lint JavaScript inside `<script>` blocks in HTML or PHP files'
```

## Contributing
Expand All @@ -34,6 +35,3 @@ Please note that modifications should follow these coding guidelines:
- Vertical whitespace helps readability, don’t be afraid to use it.

Thank you for helping out!

## Donation
[![Share the love!](https://chewbacco-stuff.s3.amazonaws.com/donate.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KXUYS4ARNHCN8)
29 changes: 26 additions & 3 deletions lib/main.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
{CompositeDisposable} = require 'atom'

module.exports =
config:
jshintExecutablePath:
default: ''
type: 'string'
description: 'Leave empty to use bundled'
lintInlineJavaScript:
type: 'boolean'
default: false
description: 'Lint JavaScript inside `<script>` blocks in HTML or PHP files'

activate: ->
scopeEmbedded = 'source.js.embedded.html'
@scopes = ['source.js', 'source.js.jsx']
@subscriptions = new CompositeDisposable
@subscriptions.add atom.config.observe 'linter-jshint.lintInlineJavaScript',
(lintInlineJavaScript) =>
if lintInlineJavaScript
@scopes.push(scopeEmbedded) unless scopeEmbedded in @scopes
else
@scopes.splice(@scopes.indexOf(scopeEmbedded), 1) if scopeEmbedded in @scopes

deactivate: ->
@subscriptions.dispose()

provideLinter: ->
if process.platform is 'win32'
jshintPath = require('path').join(__dirname, '..', 'node_modules', '.bin', 'jshint.cmd')
Expand All @@ -13,14 +33,17 @@ module.exports =
helpers = require('atom-linter')
reporter = require('jshint-json') # a string path
provider =
grammarScopes: ['source.js', 'source.js.jsx']
grammarScopes: @scopes
scope: 'file'
lintOnFly: true
lint: (textEditor) ->
lint: (textEditor) =>
exePath = atom.config.get('linter-jshint.jshintExecutablePath') || jshintPath
filePath = textEditor.getPath()
text = textEditor.getText()
parameters = ['--reporter', reporter, '--extract', 'auto', '--filename', filePath, '-']
parameters = ['--reporter', reporter, '--filename', filePath]
if textEditor.getGrammar().scopeName.indexOf('text.html') isnt -1 and 'source.js.embedded.html' in @scopes
parameters.push('--extract', 'always')
parameters.push('-')
return helpers.exec(exePath, parameters, {stdin: text}).then (output) ->
try
output = JSON.parse(output).result
Expand Down

0 comments on commit 5ce6cc3

Please sign in to comment.