Skip to content

Commit

Permalink
feat(more-rules): add more rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Heavner committed Mar 7, 2020
1 parent 54422cc commit f96af73
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
12 changes: 5 additions & 7 deletions src/rules/function-no-return-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@

import { Rule } from 'eslint'


const meta: Rule.RuleMetaData = {
docs: {
category: 'Stylistic Issues',
description: 'Check that `Function` with defined return type has RETURN statements',
description: 'Check that `Function` has a return TYPE defined',
recommended: true,
url: 'https://www.rokuroad.com/docs/rules/sub-to-function'
},
fixable: 'code',
messages: {
NO_RETURN_TYPE: 'Function {{name}} needs a return type specified'
NO_RETURN_TYPE: 'Function {{name}} needs a return type specified',
},
schema: []
schema: [],
}

const create = (context: Rule.RuleContext) => {
Expand All @@ -30,10 +28,10 @@ const create = (context: Rule.RuleContext) => {
name: node.id.name,
},
messageId: 'NO_RETURN_TYPE',
node
node,
})
}
}
},
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/rules/no-unused-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { Rule, Scope } from 'eslint'

const meta: Rule.RuleMetaData = {
docs: {
category: 'Stylistic Issues',
description: 'Check that `Function` with defined return type has RETURN statements',
category: 'Possible Errors',
description: 'Check that all function paremeters are referenced',
recommended: true,
url: 'https://www.rokuroad.com/docs/rules/sub-to-function'
},
fixable: 'code',
messages: {
UNUSED: 'Parameter {{name}} in function {{functionName}} is not used'
UNUSED:
'Parameter {{name}} in function {{functionName}} is not used. Consider removing it if it is not needed.',
},
schema: []
schema: [],
}

function findAllRefs(scope: Scope.Scope): Scope.Reference[] {
Expand All @@ -40,10 +40,10 @@ const create = (context: Rule.RuleContext) => {
name: node.name.name,
},
messageId: 'UNUSED',
node
node,
})
}
}
},
}
}

Expand Down
25 changes: 20 additions & 5 deletions tests/rules/function-no-return-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ export const test = runTest(RULE_NAME, {
`function a()
a = 5+5
end function`,

[{ message: 'Function a needs a return type specified' }]
]
[{ message: 'Function a needs a return type specified' }],
`function a() as object
return {
f: function()
return false
end function
}
end function`,
[{ message: 'Function {{name}} needs a return type specified' }],
],
].map(invalid),
valid: [
`function a() as Dynamic
Expand All @@ -26,6 +33,14 @@ export const test = runTest(RULE_NAME, {
end function`,

`function voidFunction() as Void
end function`
].map(valid)
end function`,

`function a() as object
return {
f: function() as boolean
return false
end function
}
end function`,
].map(valid),
})
27 changes: 20 additions & 7 deletions tests/rules/no-unused-params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ export const test = runTest(RULE_NAME, {
`function a(arg1, arg2) as Dynamic
end function`,

[{ message: 'Parameter arg1 in function a is not used' },
{ message: 'Parameter arg2 in function a is not used' }]
[
{
message:
'Parameter arg1 in function a is not used. Consider removing it if it is not needed.',
},
{
message:
'Parameter arg2 in function a is not used. Consider removing it if it is not needed.',
},
],
],
[
`function a(value as string) as Dynamic
a = { value: "value" }
end function`,

[{ message: 'Parameter value in function a is not used' }]
]
[
{
message:
'Parameter value in function a is not used. Consider removing it if it is not needed.',
},
],
],
].map(invalid),
valid: [
`function a(arg1, arg2) as Dynamic
Expand All @@ -36,10 +49,10 @@ export const test = runTest(RULE_NAME, {

`function voidFunction(a) as Void
obj = {
f: function()
f: function()
return a
end function
}
end function`
].map(valid)
end function`,
].map(valid),
})

0 comments on commit f96af73

Please sign in to comment.