improve error messages, fix mixed tbs/spaces, remove unused variable
This commit is contained in:
parent
fb2b2182e2
commit
437b8e169d
|
@ -10,12 +10,10 @@ import analysis.helpers;
|
||||||
import dparse.ast;
|
import dparse.ast;
|
||||||
import dparse.lexer;
|
import dparse.lexer;
|
||||||
|
|
||||||
import std.stdio;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for useless usage of the final attribute.
|
* Checks for useless usage of the final attribute.
|
||||||
*
|
*
|
||||||
* There several cases where the compiler allows them even if it's a noop.
|
* There are several cases where the compiler allows them even if it's a noop.
|
||||||
*/
|
*/
|
||||||
final class FinalAttributeChecker : BaseAnalyzer
|
final class FinalAttributeChecker : BaseAnalyzer
|
||||||
{
|
{
|
||||||
|
@ -27,14 +25,14 @@ private:
|
||||||
|
|
||||||
static struct MESSAGE
|
static struct MESSAGE
|
||||||
{
|
{
|
||||||
static immutable struct_i = "structs inherit of anything";
|
static immutable struct_i = "structs cannot be subclassed";
|
||||||
static immutable union_i = "unions inherit of anything";
|
static immutable union_i = "unions cannot be subclassed";
|
||||||
static immutable class_t = "templatized class member functions are never virtual";
|
static immutable class_t = "templated functions declared within a class are never virtual";
|
||||||
static immutable class_p = "private class member functions are never virtual";
|
static immutable class_p = "private functions declared within a class are never virtual";
|
||||||
static immutable class_f = "final class member functions are never virtual";
|
static immutable class_f = "functions declared within a final class are never virtual";
|
||||||
static immutable interface_t = "templatized interface functions are never virtual";
|
static immutable interface_t = "templated functions declared within an interface are never virtual";
|
||||||
static immutable struct_f = "struct member functions are never virtual";
|
static immutable struct_f = "functions declared within a struct are never virtual";
|
||||||
static immutable union_f = "union member functions are never virtual";
|
static immutable union_f = "functions declared within an union are never virtual";
|
||||||
static immutable func_n = "nested functions are never virtual";
|
static immutable func_n = "nested functions are never virtual";
|
||||||
static immutable func_g = "global functions are never virtual";
|
static immutable func_g = "global functions are never virtual";
|
||||||
}
|
}
|
||||||
|
@ -115,7 +113,6 @@ public:
|
||||||
override void visit(const(Declaration) d)
|
override void visit(const(Declaration) d)
|
||||||
{
|
{
|
||||||
const Parent savedParent = _parent;
|
const Parent savedParent = _parent;
|
||||||
bool privatePushed;
|
|
||||||
|
|
||||||
scope(exit)
|
scope(exit)
|
||||||
{
|
{
|
||||||
|
@ -131,8 +128,8 @@ public:
|
||||||
!d.functionDeclaration)
|
!d.functionDeclaration)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
import std.algorithm.searching : find;
|
|
||||||
import std.algorithm.iteration: filter;
|
import std.algorithm.iteration: filter;
|
||||||
|
import std.algorithm.searching : find;
|
||||||
import std.range.primitives : empty;
|
import std.range.primitives : empty;
|
||||||
|
|
||||||
if (d.attributeDeclaration && d.attributeDeclaration.attribute)
|
if (d.attributeDeclaration && d.attributeDeclaration.attribute)
|
||||||
|
@ -214,10 +211,10 @@ public:
|
||||||
|
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
import std.stdio : stderr;
|
|
||||||
import std.format : format;
|
|
||||||
import analysis.config : StaticAnalysisConfig, Check;
|
import analysis.config : StaticAnalysisConfig, Check;
|
||||||
import analysis.helpers : assertAnalyzerWarnings;
|
import analysis.helpers : assertAnalyzerWarnings;
|
||||||
|
import std.stdio : stderr;
|
||||||
|
import std.format : format;
|
||||||
|
|
||||||
StaticAnalysisConfig sac;
|
StaticAnalysisConfig sac;
|
||||||
sac.final_attribute_check = Check.enabled;
|
sac.final_attribute_check = Check.enabled;
|
||||||
|
@ -331,5 +328,11 @@ public:
|
||||||
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
|
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
|
||||||
), sac);
|
), sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
private: final class Foo {public: private final void foo(){}} // [warn]: %s
|
||||||
|
}c.format(
|
||||||
|
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
|
||||||
|
), sac);
|
||||||
|
|
||||||
stderr.writeln("Unittest for FinalAttributeChecker passed.");
|
stderr.writeln("Unittest for FinalAttributeChecker passed.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue