-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #557 from protofire/interface-starts-with-i
New Rule: Interface starts with i
- Loading branch information
Showing
6 changed files
with
145 additions
and
23 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,50 @@ | ||
--- | ||
warning: "This is a dynamically generated file. Do not edit manually." | ||
layout: "default" | ||
title: "interface-starts-with-i | Solhint" | ||
--- | ||
|
||
# interface-starts-with-i | ||
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational) | ||
![Default Severity Badge warning](https://img.shields.io/badge/Default%20Severity-warning-undefined) | ||
|
||
## Description | ||
Solidity Interfaces names should start with an `I` | ||
|
||
## Options | ||
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warning. | ||
|
||
### Example Config | ||
```json | ||
{ | ||
"rules": { | ||
"interface-starts-with-i": "warning" | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Examples | ||
### 👍 Examples of **correct** code for this rule | ||
|
||
#### Interface name starts with I | ||
|
||
```solidity | ||
interface IFoo { function foo () external; } | ||
``` | ||
|
||
### 👎 Examples of **incorrect** code for this rule | ||
|
||
#### Interface name doesnt start with I | ||
|
||
```solidity | ||
interface Foo { function foo () external; } | ||
``` | ||
|
||
## Version | ||
This rule is introduced in the latest version. | ||
|
||
## Resources | ||
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/best-practises/interface-starts-with-i.js) | ||
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/best-practises/interface-starts-with-i.md) | ||
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/best-practises/interface-starts-with-i.js) |
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,45 @@ | ||
const BaseChecker = require('../base-checker') | ||
|
||
const ruleId = 'interface-starts-with-i' | ||
const meta = { | ||
type: 'naming', | ||
docs: { | ||
description: 'Solidity Interfaces names should start with an `I`', | ||
category: 'Style Guide Rules', | ||
examples: { | ||
good: [ | ||
{ | ||
description: 'Interface name starts with I', | ||
code: `interface IFoo { function foo () external; }`, | ||
}, | ||
], | ||
bad: [ | ||
{ | ||
description: 'Interface name doesnt start with I', | ||
code: `interface Foo { function foo () external; }`, | ||
}, | ||
], | ||
}, | ||
}, | ||
isDefault: false, | ||
recommended: false, | ||
defaultSetup: 'warning', | ||
schema: [], | ||
} | ||
|
||
class InterfaceStartsWithIChecker extends BaseChecker { | ||
constructor(reporter) { | ||
super(reporter, ruleId, meta) | ||
} | ||
|
||
ContractDefinition(node) { | ||
if (node.kind !== 'interface') return | ||
const interfaceName = node.name | ||
|
||
if (!interfaceName.startsWith('I')) { | ||
this.error(node, `Interface name '${interfaceName}' must start with "I"`) | ||
} | ||
} | ||
} | ||
|
||
module.exports = InterfaceStartsWithIChecker |
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,23 @@ | ||
const assert = require('assert') | ||
const { processStr } = require('../../../lib/index') | ||
|
||
const config = { | ||
rules: { 'interface-starts-with-i': 'error' }, | ||
} | ||
|
||
describe('Linter - interface-starts-with-i', () => { | ||
it('should raise error for interface not starting with I', () => { | ||
const code = 'interface Foo {}' | ||
const report = processStr(code, config) | ||
|
||
assert.equal(report.errorCount, 1) | ||
assert.ok(report.messages[0].message === `Interface name 'Foo' must start with "I"`) | ||
}) | ||
|
||
it('should not raise error for interface starting with I', () => { | ||
const code = 'interface IFoo {}' | ||
|
||
const report = processStr(code, config) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
}) |