An ESLint plugin with a set of rules
- Install
eslint
peer dependency:
npm i eslint --save-dev
- Install
eslint-plugin-kopytko
:
npm i @dazn/eslint-plugin-kopytko --save-dev
In .eslintrc
:
{
"extends": "plugin:@dazn/kopytko/recommended",
"plugins": ["@dazn/kopytko"]
}
A rule to use with Kopytko Packager 's importing mechanism and Kopytko Unit Testing Framework 's mocking mechanism.
Enforces a proper alphabetical and path-specific order of @import
and @mock
annotations:
- imports or mocks from external packages have to be before local ones
@mock
annotations have to be after all@import
annotations- alphabetical order of external packages names
- alphabetical order of paths
- nested paths have to be declared after their root path
Example of incorrect code:
' @import /components/main-function.brs
' @import /components/nested/another-function.brs
' @import /components/nested/cool-function.brs
' @import /components/nested/some-function.brs from package-name
' @mock /components/mocked-function.brs
' @mock /components/some-mocked-function.brs from package-name
Example of correct code:
' @import /components/nested/some-function.brs from package-name
' @mock /components/some-mocked-function.brs from package-name
' @import /components/main-function.brs
' @import /components/nested/another-function.brs
' @import /components/nested/cool-function.brs
' @mock /components/mocked-function.brs
Example of incorrect code:
' @mock /components/mocked-function.brs
' @import /components/main-function.brs
' @import /components/nested/another-function.brs
' @import /components/nested/cool-function.brs
Example of correct code:
' @import /components/main-function.brs
' @import /components/nested/another-function.brs
' @import /components/nested/cool-function.brs
' @mock /components/mocked-function.brs
Example of incorrect code:
' @import /components/a-function.brs from package-name
' @import /components/some-function.brs from another-package-name
' @mock /components/another-mocked-function.brs from package-name
' @mock /components/some-mocked-function.brs from another-package-name
' @import /components/main-function.brs
' @mock /components/mocked-function.brs
Example of correct code:
' @import /components/some-function.brs from another-package-name
' @import /components/a-function.brs from package-name
' @mock /components/some-mocked-function.brs from another-package-name
' @mock /components/another-mocked-function.brs from package-name
' @import /components/main-function.brs
' @mock /components/mocked-function.brs
Example of incorrect code:
' @import /components/nested/another-function.brs
' @import /components/main-function.brs
' @import /components/nested/cool-function.brs
' @mock /components/some-mocked-function.brs
' @mock /components/mocked-function.brs
Example of correct code:
' @import /components/main-function.brs
' @import /components/nested/another-function.brs
' @import /components/nested/cool-function.brs
' @mock /components/mocked-function.brs
' @mock /components/some-mocked-function.brs
Check if function with defined return type has return
statement.
Examples of incorrect code for this rule:
function calc() as Integer
result = 1 + 2
end function
Examples of correct code for this rule:
function calc() as Integer
result = 1 + 2
return result
end function
Enforces consistent indentation of block, array and object expressions, and function declarations
Examples of incorrect code for this rule, set to 2 characters:
sub test()
example = [
1,
2,
]
if (1 = 1)
superFunction({
a: "a",
b: "b",
c: "c",
})
end if
end sub
sub another()
superFunction({})
end sub
Examples of correct code for this rule, set to 2 characters:
sub test()
example = [
1,
2,
]
if (1 = 1)
superFunction({
a: "a",
b: "b",
c: "c",
})
end if
end sub
sub another()
superFunction({})
end sub
Enforces a trailing comma after every property of multiline associative array
The --fix
option on the command line can automatically fix some of the problems reported by this rule.
Examples of incorrect code for this rule:
test = {
a: "a",
b: "b"
}
Examples of correct code for this rule:
test = {
a: "a",
b: "b",
}
Check that all variables are declared.
Examples of incorrect code for this rule:
sub a()
print(foo)
end sub
Examples of correct code for this rule:
sub a()
foo = "bar"
print(foo)
end sub
Check that sub
doesn't have a return type.
Examples of incorrect code for this rule:
sub a() as Dynamic
end sub
Examples of correct code for this rule:
sub a()
print("foo")
end sub
Disallows the use of print
.
Disallows the use of stop
.