This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added no-unnecessary-else Rule * Changed year to 2019 under License * Changed name of the rule to 'unnecessary-else' * Removed comments like valid from test.ts.lint file * Modified the description, rationale and the FAILURE_STRING * Added codeExamples * Changed the Logic and Added new testcases * Incorporated review comments and Added more testcases * Revert "Incorporated review comments and Added more testcases" This reverts commit 2e0825f. * Incorporated review comments and Added more Testcases * Modified the logic and error message * Modified Code Examples * Fixed linting errors * Optimized the rule logic
- Loading branch information
Showing
37 changed files
with
659 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as Lint from "../../index"; | ||
|
||
// tslint:disable: object-literal-sort-keys | ||
export const codeExamples = [ | ||
{ | ||
description: | ||
'Disallows "else" following "if" blocks ending with "return", "break", "continue" or "throw" statement. ', | ||
config: Lint.Utils.dedent` | ||
"rules": { "unnecessary-else": true } | ||
`, | ||
pass: Lint.Utils.dedent` | ||
if (someCondition()) { | ||
return; | ||
} | ||
// some code here | ||
if (someCondition()) { | ||
continue; | ||
} | ||
// some code here | ||
if (someCondition()) { | ||
throw; | ||
} | ||
// some code here | ||
if (someCondition()) { | ||
break; | ||
} | ||
// some code here | ||
`, | ||
fail: Lint.Utils.dedent` | ||
if (someCondition()) { | ||
return; | ||
} else { | ||
// some code here | ||
} | ||
if (someCondition()) { | ||
break; | ||
} else { | ||
// some code here | ||
} | ||
if (someCondition()) { | ||
throw; | ||
} else { | ||
// some code here | ||
} | ||
if (someCondition()) { | ||
continue; | ||
} else { | ||
// some code here | ||
} | ||
`, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.