├── .flowconfig ├── readme └── example.png ├── package.json ├── README.md ├── LICENSE ├── node └── flow-lint.js └── main.js /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [options] 8 | -------------------------------------------------------------------------------- /readme/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikunia/brackets-flow-lint/master/readme/example.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "brackets-flow-lint", 3 | "version": "0.1.1", 4 | "description": "Facebook Flow support for Brackets", 5 | "author": "Ole Kröger ", 6 | "main": "main.js", 7 | "keywords": [ 8 | "brackets", 9 | "flow", 10 | "facebook", 11 | "lint" 12 | ], 13 | "homepage": "https://github.com/Wikunia/brackets-flow-lint", 14 | "license": "MIT" 15 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flow linter for Brackets 2 | 3 | 4 | Lint your javascript files using [flow](http://flowtype.org/) by Facebook. 5 | 6 | ## Usage 7 | 8 | + Install [flow](http://flowtype.org/docs/getting-started.html#_) 9 | + Add `/* @flow */` to the js files you want to check 10 | 11 | If you changed the linting options inside the preference file you might need to add `flow-lint` to your linters inside the `brackets.json` 12 | 13 | 14 | ## Simple example 15 | 16 | ![simple example](readme/example.png) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ole Kröger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /node/flow-lint.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /* 3 | * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, 26 | maxerr: 50, node: true */ 27 | /*global */ 28 | 29 | (function () { 30 | "use strict"; 31 | 32 | var exec = require('child_process').exec; 33 | var fs = require('fs'); 34 | 35 | function execute(command, callback){ 36 | exec(command, function(error, stdout, stderr){ callback(error,stdout,stderr); }); 37 | }; 38 | 39 | function getFlowErrors(prPath,callback){ 40 | if (prPath.substr(-1) != '/') { 41 | prPath += '/'; 42 | } 43 | // if there is no flowconfig file => run flow init 44 | if (!fs.existsSync(prPath+'.flowconfig')) { 45 | execute("cd "+prPath+" && flow init", function(err,data,stderr){ 46 | flowJson(); 47 | console.log("here 2"); 48 | }); 49 | } else { 50 | console.log("here"); 51 | flowJson(); 52 | } 53 | 54 | 55 | function flowJson() { 56 | execute("cd "+prPath+" && flow --json", function(err,data,stderr){ 57 | try { 58 | callback(null,JSON.parse(data)); 59 | } catch(e) { 60 | callback(e,null); 61 | } 62 | }); 63 | } 64 | }; 65 | 66 | function init(domainManager) { 67 | if (!domainManager.hasDomain("flow-lint")) { 68 | domainManager.registerDomain("flow-lint", {major: 0, minor: 1}); 69 | } 70 | domainManager.registerCommand( 71 | "flow-lint", // domain name 72 | "getErrors", // command name 73 | getFlowErrors, // command handler function 74 | true 75 | ); 76 | } 77 | 78 | exports.init = init; 79 | 80 | }()); 81 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /* 3 | * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | 26 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, 27 | maxerr: 50, browser: true */ 28 | /*global $, define, brackets */ 29 | 30 | define(function (require, exports, module) { 31 | "use strict"; 32 | 33 | var ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), 34 | ProjectManager = brackets.getModule("project/ProjectManager"), 35 | NodeDomain = brackets.getModule("utils/NodeDomain"), 36 | CodeInspection = brackets.getModule("language/CodeInspection"); 37 | 38 | var flowNode = new NodeDomain("flow-lint", ExtensionUtils.getModulePath(module, "node/flow-lint")); 39 | 40 | 41 | function flowLint(text,fullPath) { 42 | var deferred = $.Deferred(); 43 | var result = {errors: []}; 44 | flowNode.exec("getErrors",ProjectManager.getInitialProjectPath()) 45 | .done(function (flow) { 46 | if (flow.passed) { 47 | deferred.resolve(null); 48 | } else { 49 | for (var i = 0; i < flow.errors.length; i++) { 50 | var cFError = flow.errors[i]; 51 | for (var j = 0; j < cFError.message.length; j++) { 52 | var cFErrorMsg = cFError.message[j]; 53 | if (cFErrorMsg.path == fullPath) { 54 | result.errors.push({ 55 | pos: {line:cFErrorMsg.line-1, ch:cFErrorMsg.start}, 56 | endPos: {line:cFErrorMsg.endLine-1, ch:cFErrorMsg.end}, 57 | message:cFErrorMsg.descr, 58 | type: CodeInspection.Type.WARNING 59 | }); 60 | } 61 | } 62 | } 63 | deferred.resolve(result); 64 | } 65 | 66 | }).fail(function (err) { 67 | deferred.resolve(null); 68 | }); 69 | return deferred.promise(); 70 | } 71 | 72 | CodeInspection.register("javascript", { 73 | name: "flow-lint", 74 | scanFileAsync: flowLint 75 | }); 76 | 77 | }); 78 | --------------------------------------------------------------------------------