forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix - no-use-before-declare - exception for destructuring w/ rename (
palantir#3876) * ignoring identifiers whose parent is a binding element * check that ignored identifier is propname of binding element * additional tests
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license | ||
* Copyright 2013 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: "Check that referenced variables are declared beforehand (default)", | ||
config: Lint.Utils.dedent` | ||
"rules": { "no-use-before-declare": true } | ||
`, | ||
pass: Lint.Utils.dedent` | ||
var hello = 'world'; | ||
var foo; | ||
console.log(hello, foo, capitalize(hello)); | ||
// 'world', undefined, 'WORLD' | ||
function capitalize(val) { | ||
return val.toUpperCase(); | ||
} | ||
import { default as foo1 } from "./lib"; | ||
import foo2 from "./lib"; | ||
import _, { map, foldl } from "./underscore"; | ||
import * as foo3 from "./lib"; | ||
import "./lib"; | ||
function declaredImports() { | ||
console.log(foo1); | ||
console.log(foo2); | ||
console.log(foo3); | ||
map([], (x) => x); | ||
} | ||
`, | ||
fail: Lint.Utils.dedent` | ||
console.log(hello, foo); | ||
var hello = 'world'; | ||
var foo; | ||
function undeclaredImports() { | ||
console.log(foo1); | ||
console.log(foo2); | ||
console.log(foo3); | ||
map([], (x) => x); | ||
} | ||
import { default as foo1 } from "./lib"; | ||
import foo2 from "./lib"; | ||
import _, { map, foldl } from "./underscore"; | ||
import * as foo3 from "./lib"; | ||
import "./lib"; | ||
`, | ||
}, | ||
]; |
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