{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/3437","labels_url":"https://api.github.com/repos/eslint/eslint/issues/3437/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/3437/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/3437/events","html_url":"https://github.com/eslint/eslint/issues/3437","id":101776178,"number":3437,"title":"Not all eslint 1.0.0 formatters work in grunt","user":{"login":"pkosenko","id":4556807,"avatar_url":"https://avatars.githubusercontent.com/u/4556807?v=3","gravatar_id":"","url":"https://api.github.com/users/pkosenko","html_url":"https://github.com/pkosenko","followers_url":"https://api.github.com/users/pkosenko/followers","following_url":"https://api.github.com/users/pkosenko/following{/other_user}","gists_url":"https://api.github.com/users/pkosenko/gists{/gist_id}","starred_url":"https://api.github.com/users/pkosenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkosenko/subscriptions","organizations_url":"https://api.github.com/users/pkosenko/orgs","repos_url":"https://api.github.com/users/pkosenko/repos","events_url":"https://api.github.com/users/pkosenko/events{/privacy}","received_events_url":"https://api.github.com/users/pkosenko/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-08-19T00:02:07Z","updated_at":"2015-08-20T00:28:01Z","closed_at":"2015-08-19T23:02:10Z","body":"I notice that not all the formatters that ship with eslint 1.0.0 actually work with Grunt, although they do work on the eslint command line.  I moved the folder over to another location accessible by grunt and ran the following (running node.js on Windows 7):\r\n\r\n    // Using gruntify-eslint\r\n    eslint: {\r\n      options: {\r\n        format: \"./formatters/compact\",\r\n       },\r\n\r\nI replaced \"compact\" with the filenames (minus .js extension) and got \r\nthe following:\r\n\r\ncheckstyle\t// works\r\ncompact\t\t// works\r\njslint-xml\t// Warning: Formatter ./formatters/jslint-xml not found Use --force to continue.\r\njson\t\t// works\r\njunit\t\t// Warning: Formatter ./formatters/junit not found Use --force to continue.\r\nstylish\t\t// Warning: Formatter ./formatters/stylish not found Use --force to continue.\r\ntap\t\t// Warning: Formatter ./formatters/tap not found Use --force to continue.\r\nunix\t\t// works\r\n\r\nThe failure of \"stylish\" is strange, since it is the DEFAULT, and seems to work when it is accessed as the default (with no explicit object reference).\r\n\r\nI notice that the function processing occurs here is cli.js:\r\n\r\n    formatter = engine.getFormatter(format);\r\n    if (!formatter) {\r\n        console.error(\"Could not find formatter '%s'.\", format);\r\n        return false;\r\n    }\r\n\r\nThat apparently passes, since the error message is NOT \"Could not find formatter . . .\".\r\n\r\nSo I am guessing that the problem is somewhere in the try block of getFormatter(), since I have the files located in the DEFAULT location (\"./formatters/\" + format\"), and the getFormatter is loading the \r\nformatter MODULES (all formatters are exported as modules).\r\n\r\ngetFormatter() is in cli-engine.js:\r\n\r\n\r\n    getFormatter: function(format) {\r\n\r\n        var formatterPath;\r\n\r\n        // default is stylish\r\n        format = format || \"stylish\";\r\n\r\n        // only strings are valid formatters\r\n        if (typeof format === \"string\") {\r\n\r\n            // replace \\ with / for Windows compatibility\r\n            format = format.replace(/\\\\/g, \"/\");\r\n\r\n            // if there's a slash, then it's a file\r\n            if (format.indexOf(\"/\") > -1) {\r\n                formatterPath = path.resolve(process.cwd(), format);\r\n            } else {\r\n                formatterPath = \"./formatters/\" + format;\r\n            }\r\n\r\n            try {\r\n                return require(formatterPath);\r\n            } catch (ex) {\r\n                return null;\r\n            }\r\n\r\n        } else {\r\n            return null;\r\n        }\r\n    }\r\n\r\n*****************\r\n\r\nNote that the formatters with grunt problems WORK when run from eslint directly (rather than grunt):\r\n\r\n\"tap\" formatter:\r\n\r\n$ eslint -f tap librivox_search_with_views.js\r\nTAP version 13\r\n1..1\r\nnot ok 1 - librivox_search_with_views.js\r\n  ---\r\n  message: Expected indentation of 0 characters.\r\n  severity: error\r\n  data:\r\n    line: 3\r\n    column: 0\r\n    ruleId: indent\r\n  messages:\r\n    - message: Trailing spaces not allowed.\r\n      severity: error\r\n      data:\r\n        line: 142\r\n        column: 10\r\n        ruleId: no-trailing-spaces\r\n  ...\r\n\r\n\"jslint-xml\" formatter\r\n\r\n$ eslint -f jslint-xml librivox_search_with_views.js\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint><file name=\"librivox_search_with_views.js\"><issue line=\"3\" char=\"0\" evidence=\"    var librivoxSearch = angular.module(&apos\r\n;librivoxSearch&apos;, [&apos;ui.router&apos;, &apos;blndspt.ngPerformance&apos;]);\" reason=\"Expected indentation of 0 characters. (indent)\" /><issue line=\"4\" char=\"0\" e\r\nvidence=\"    librivoxSearch.controller(&apos;librivoxSearchController&apos;, function ($scope, $http, searchData, $state, $location) {\" reason=\"Expected indentation of 0\r\n characters. (indent)\" />\r\n\r\n\"junit\" formatter\r\n\r\n\r\n$ eslint -f junit librivox_search_with_views.js\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<testsuites>\r\n<testsuite package=\"org.eslint\" time=\"0\" tests=\"110\" errors=\"110\" name=\"librivox_search_with_views.js\">\r\n<testcase time=\"0\" name=\"org.eslint.indent\"><failure message=\"Expected indentation of 0 characters.\"><![CDATA[line 3, col 0, Error - Expected indentation of 0 characters\r\n. (indent)]]></failure></testcase>\r\n<testcase time=\"0\" name=\"org.eslint.indent\"><failure message=\"Expected indentation of 0 characters.\"><![CDATA[line 4, col 0, Error - Expected indentation of 0 characters\r\n. (indent)]]></failure></testcase>\r\n"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/132835998","html_url":"https://github.com/eslint/eslint/issues/3437#issuecomment-132835998","issue_url":"https://api.github.com/repos/eslint/eslint/issues/3437","id":132835998,"user":{"login":"pkosenko","id":4556807,"avatar_url":"https://avatars.githubusercontent.com/u/4556807?v=3","gravatar_id":"","url":"https://api.github.com/users/pkosenko","html_url":"https://github.com/pkosenko","followers_url":"https://api.github.com/users/pkosenko/followers","following_url":"https://api.github.com/users/pkosenko/following{/other_user}","gists_url":"https://api.github.com/users/pkosenko/gists{/gist_id}","starred_url":"https://api.github.com/users/pkosenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkosenko/subscriptions","organizations_url":"https://api.github.com/users/pkosenko/orgs","repos_url":"https://api.github.com/users/pkosenko/repos","events_url":"https://api.github.com/users/pkosenko/events{/privacy}","received_events_url":"https://api.github.com/users/pkosenko/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T00:28:01Z","updated_at":"2015-08-20T00:28:01Z","body":"Actually, the code in gruntify-eslint points to eslint.getFormatters() as the processing function that is handling the reference to the formatters (either module name or path).  So it looks to me like eslint should be looking into that.  It doesn't look like a grunt issue at all.\r\n\r\n        formatter = eslint.getFormatter(options.format);\r\n        if (!formatter) {\r\n            grunt.warn(\"Formatter \" + options.format + \" not found\");\r\n            return;\r\n        }\r\n\r\nThat is where the error is being generated. eslint.getFormatter() is returning a bad formatter module reference."}}