Skip to content
This repository
Browse code

added support to switch between jshint / jslint

  • Loading branch information...
commit da4d6e83304626cb5bb5ea3737fca1271fa8b19e 1 parent d25d29c
Dale Harvey authored

Showing 3 changed files with 5,728 additions and 11 deletions. Show diff stats Hide diff stats

  1. +7 1 flymake-jshint.el
  2. +20 10 jshint-mode.js
  3. +5,701 0 jslint.js
8 flymake-jshint.el
@@ -12,6 +12,11 @@
12 12
13 13 (require 'flymake)
14 14
  15 +(defcustom jshint-mode-mode "jshint"
  16 + "Can use eith jshint or jslint"
  17 + :type 'string
  18 + :group 'flymake-jshint)
  19 +
15 20 (defcustom jshint-mode-node-program "node"
16 21 "The program name to invoke node.js."
17 22 :type 'string
@@ -65,9 +70,10 @@
65 70 (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace))
66 71 (local-file (file-relative-name temp-file
67 72 (file-name-directory buffer-file-name)))
68   - (jshint-url (format "http://%s:%d/jshint" jshint-mode-host jshint-mode-port)))
  73 + (jshint-url (format "http://%s:%d/check" jshint-mode-host jshint-mode-port)))
69 74 (list "curl" (list "--form" (format "source=<%s" local-file)
70 75 "--form" (format "filename=%s" local-file)
  76 + "--form" (format "mode=%s" jshint-mode-mode)
71 77 jshint-url)))))
72 78
73 79 (setq flymake-allowed-file-name-masks
30 jshint-mode.js
... ... @@ -1,3 +1,4 @@
  1 +/*jslint eqeqeq: true */
1 2 /* HTTP interface to JSHint.
2 3
3 4 curl --form source="<path/to/my.js" --form=filename="my.js" http://127.0.0.1:3003/jshint
@@ -10,6 +11,7 @@
10 11
11 12 var http = require('http'),
12 13 formidable = require('formidable'),
  14 + JSLINT = require('./jslint'),
13 15 JSHINT = require('./jshint');
14 16
15 17 function getOpt(key) {
@@ -23,7 +25,6 @@ function outputErrors(errors) {
23 25
24 26 function out(s) {
25 27 output.push(s + '\n');
26   -
27 28 }
28 29
29 30 for (i = 0; i < errors.length; i += 1) {
@@ -37,13 +38,19 @@ function outputErrors(errors) {
37 38 return output.join('');
38 39 }
39 40
40   -function lintify(sourcedata, filename) {
  41 +function lintify(mode, sourcedata, filename) {
41 42
42   - // TODO: parse options from source file
43   - var passed = JSHINT.JSHINT(sourcedata, {});
  43 + var passed;
44 44
45   - return passed ? "jslint: No problems found in " + filename + "\n"
46   - : outputErrors(JSHINT.JSHINT.errors);
  45 + if (mode == "jshint") {
  46 + passed = JSHINT.JSHINT(sourcedata, {});
  47 + return passed ? "jshint: No problems found in " + filename + "\n"
  48 + : outputErrors(JSHINT.JSHINT.errors);
  49 + } else {
  50 + passed = JSLINT.JSLINT(sourcedata, {eqeqeq:true});
  51 + return passed ? "jslint: No problems found in " + filename + "\n"
  52 + : outputErrors(JSLINT.JSLINT.errors);
  53 + }
47 54 }
48 55
49 56 var port = getOpt("--port") || 3003,
@@ -51,11 +58,14 @@ var port = getOpt("--port") || 3003,
51 58
52 59 http.createServer(function(req, res) {
53 60
54   - if (req.url === '/jshint' && req.method.toUpperCase() === 'POST') {
  61 + if (req.url === '/check' && req.method.toUpperCase() === 'POST') {
55 62 var form = new formidable.IncomingForm();
56 63 form.parse(req, function(err, fields, files) {
57   - console.log('Applying JSHint to: ' + (fields.filename || 'anonymous'));
58   - var results = lintify(fields.source, fields.filename);
  64 + var mode = (fields.mode && fields.mode == "jslint") ? "jslint" : "jshint";
  65 +
  66 + console.log('Applying \'' + mode + '\' to: ' + (fields.filename || 'anonymous'));
  67 +
  68 + var results = lintify(mode, fields.source, fields.filename);
59 69 res.writeHead(200, {'Content-Type': 'text/plain'});
60 70 res.end(results);
61 71 });
@@ -63,7 +73,7 @@ http.createServer(function(req, res) {
63 73 }
64 74
65 75 res.writeHead(200, {'Content-Type': 'text/plain'});
66   - res.end("hey guys");
  76 + res.end("hello from jshint-mode");
67 77
68 78 }).listen(port, host);
69 79
5,701 jslint.js
5,701 additions, 0 deletions not shown

0 comments on commit da4d6e8

Please sign in to comment.
Something went wrong with that request. Please try again.