Skip to content

Commit

Permalink
Disable no-else-return rule
Browse files Browse the repository at this point in the history
Doc updates also
  • Loading branch information
wcjohnson committed Oct 19, 2017
1 parent 8fb9ef8 commit 6cfb623
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ Example configuration (with React):
}
```

When running `eslint` from the CLI, you must tell it to process LightScript file extensions:

```
$ eslint --ext .js,.lsc src
```

### Live Linting

#### Visual Studio Code

- Set up eslint for your project as above. Verify that eslint lints correctly from the CLI.
- Install the `ESLint` extension for VSCode: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
- Tell VSCode to live-lint LightScript files by adding the following entry to your VSCode options (workspace or global):
```
"eslint.validate": ["javascript", "javascriptreact", "lightscript"]
```

### Broken Rules

The following lint rules are either buggy, broken, or do not make sense in the context of LightScript. They are disabled at the code level and will not run even if you enable them in your configuration.

- `no-unexpected-multiline`
- `no-else-return`

### Contributing

Issues: https://github.com/wcjohnson/lightscript/issues
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ var codeFrame = require("babel-code-frame");
var lscPlugin = require("@oigroup/babel-plugin-lightscript");
var lscTooling = require("@oigroup/babel-plugin-lightscript/lib/tooling");

var lightScriptDisabledRulesTable = {
"no-unexpected-multiline": true,
"no-else-return": true
};

var hasPatched = false;
var eslintOptions = {};

Expand Down Expand Up @@ -370,13 +375,14 @@ function monkeypatch(modules) {
};

// monkeypatch rules
// in eslint 4, rule getter is a class whereas it was an object in 3...
var emptyRule = function() { return {}; };
emptyRule.create = function() { return {}; };
var rules = getModule(eslintMod, "./rules");
var _get = rules.get || rules.prototype.get;
var nextGet = function get(ruleId) {
// disable no-unexpected-multiline, lsc compiler deals with this
if (ruleId === "no-unexpected-multiline") {
// disable invalid or broken rules
if (ruleId && lightScriptDisabledRulesTable[ruleId]) {
return emptyRule;
} else {
return _get.call(this || rules, ruleId);
Expand Down
14 changes: 14 additions & 0 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ a = b -> c
);
});

it("no-else-return disabled", () => {
verifyAndAssertMessages(
unpad(`
f() ->
if true:
{ three: 3 }
else:
{}
`),
{ "no-else-return": 2 },
[]
);
});

//////////// end lsc tests
});

Expand Down

0 comments on commit 6cfb623

Please sign in to comment.