-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no-cycle: real rule! first draft, perf is likely atrocious
- Loading branch information
Showing
10 changed files
with
104 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import foo from "./depth-zero" | ||
export { foo } |
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,5 @@ | ||
import './depth-two' | ||
|
||
export function bar() { | ||
return "side effects???" | ||
} |
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,2 @@ | ||
import * as two from "./depth-two" | ||
export { two } |
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,2 @@ | ||
import { foo } from "./depth-one" | ||
export { foo } |
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 @@ | ||
// export function foo() {} |
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,55 @@ | ||
import { test as _test, testFilePath } from '../utils' | ||
|
||
import { RuleTester } from 'eslint' | ||
|
||
const ruleTester = new RuleTester() | ||
, rule = require('rules/no-cycle') | ||
|
||
const error = message => ({ ruleId: 'no-cycle', message }) | ||
|
||
const test = def => _test(Object.assign(def, { | ||
filename: testFilePath("./cycles/depth-zero.js") | ||
})) | ||
|
||
// describe.only("no-cycle", () => { | ||
ruleTester.run('no-cycle', rule, { | ||
valid: [ | ||
// this rule doesn't care if the cycle length is 0 | ||
test({ code: 'import foo from "./foo.js"'}), | ||
|
||
test({ code: 'import _ from "lodash"' }), | ||
test({ code: 'import foo from "@scope/foo"' }), | ||
test({ code: 'var _ = require("lodash")' }), | ||
test({ code: 'var find = require("lodash.find")' }), | ||
test({ code: 'var foo = require("./foo")' }), | ||
test({ code: 'var foo = require("../foo")' }), | ||
test({ code: 'var foo = require("foo")' }), | ||
test({ code: 'var foo = require("./")' }), | ||
test({ code: 'var foo = require("@scope/foo")' }), | ||
test({ code: 'var bar = require("./bar/index")' }), | ||
test({ code: 'var bar = require("./bar")' }), | ||
test({ | ||
code: 'var bar = require("./bar")', | ||
filename: '<text>', | ||
}), | ||
], | ||
invalid: [ | ||
test({ | ||
code: 'import { foo } from "./depth-one"', | ||
errors: [error("Dependency cycle detected.")] | ||
}), | ||
test({ | ||
code: 'import { foo } from "./depth-two"', | ||
errors: [error("Dependency cycle via ./depth-one:1")] | ||
}), | ||
test({ | ||
code: 'import { two } from "./depth-three-star"', | ||
errors: [error("Dependency cycle via ./depth-two:1=>./depth-one:1")] | ||
}), | ||
test({ | ||
code: 'import { bar } from "./depth-three-indirect"', | ||
errors: [error("Dependency cycle via ./depth-two:1=>./depth-one:1")] | ||
}), | ||
], | ||
}) | ||
// }) |
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