Catch more useless uses of 'abstract'
This commit is contained in:
parent
03454d6b65
commit
0b28dfa652
|
@ -37,10 +37,18 @@ class FunctionAttributeCheck : BaseAnalyzer
|
||||||
inInterface--;
|
inInterface--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(const AttributeDeclaration dec)
|
||||||
|
{
|
||||||
|
if (inInterface > 0 && dec.attribute.storageClass !is null
|
||||||
|
&& dec.attribute.storageClass.token == tok!"abstract")
|
||||||
|
{
|
||||||
|
addErrorMessage(dec.attribute.storageClass.token.line,
|
||||||
|
dec.attribute.storageClass.token.column, KEY, ABSTRACT_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override void visit(const Declaration dec)
|
override void visit(const Declaration dec)
|
||||||
{
|
{
|
||||||
if (dec.functionDeclaration is null)
|
|
||||||
goto end;
|
|
||||||
if (dec.attributes.length == 0)
|
if (dec.attributes.length == 0)
|
||||||
goto end;
|
goto end;
|
||||||
foreach (attr; dec.attributes)
|
foreach (attr; dec.attributes)
|
||||||
|
@ -49,15 +57,14 @@ class FunctionAttributeCheck : BaseAnalyzer
|
||||||
continue;
|
continue;
|
||||||
if (attr.storageClass.token == tok!"abstract" && inInterface > 0)
|
if (attr.storageClass.token == tok!"abstract" && inInterface > 0)
|
||||||
{
|
{
|
||||||
addErrorMessage(dec.functionDeclaration.name.line,
|
addErrorMessage(attr.storageClass.token.line,
|
||||||
dec.functionDeclaration.name.column, KEY,
|
attr.storageClass.token.column, KEY, ABSTRACT_MESSAGE);
|
||||||
"'abstract' attribute on interface function has"
|
|
||||||
~ " no effect.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (attr.storageClass.token == tok!"const"
|
if (dec.functionDeclaration !is null
|
||||||
|
&& (attr.storageClass.token == tok!"const"
|
||||||
|| attr.storageClass.token == tok!"inout"
|
|| attr.storageClass.token == tok!"inout"
|
||||||
|| attr.storageClass.token == tok!"immutable")
|
|| attr.storageClass.token == tok!"immutable"))
|
||||||
{
|
{
|
||||||
import std.string : format;
|
import std.string : format;
|
||||||
immutable string attrString = str(attr.storageClass.token.type);
|
immutable string attrString = str(attr.storageClass.token.type);
|
||||||
|
@ -73,5 +80,6 @@ class FunctionAttributeCheck : BaseAnalyzer
|
||||||
|
|
||||||
int inInterface;
|
int inInterface;
|
||||||
|
|
||||||
|
private enum ABSTRACT_MESSAGE = "'abstract' attribute is redundant in interface declarations";
|
||||||
private enum KEY = "dscanner.confusing.function_attributes";
|
private enum KEY = "dscanner.confusing.function_attributes";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue