| Severity | Warning |
| Reported by | Metalama.Extensions.Architecture |
| Message | The <DeclarationKind> '<Declaration>' does not respect the naming convention set by a fabric. The <DeclarationKind> name should match the "<Pattern>" pattern. |
Cause
In a fabric, you can select declarations and require their names to follow a convention with the MustRespectNamingConvention method, where * matches any substring, or with the MustRespectRegexNamingConvention method, which takes a regular expression.
Metalama reports LAMA0906 for each selected declaration whose name doesn't match the pattern. In the message, <Declaration> is the declaration, <DeclarationKind> its kind, and <Pattern> the pattern as a regular expression. When you use MustRespectNamingConvention, the message shows the regular expression that Metalama generates from your pattern, for example ^.*Reader$ for *Reader.
In the following example, a fabric requires all classes derived from TextReader to have a name ending with Reader, but the TextLoader class doesn't respect this convention.
1using Metalama.Extensions.Architecture;
2using Metalama.Framework.Fabrics;
3using System.IO;
4
5namespace Doc.LAMA0906.Error;
6
7internal class Fabric : ProjectFabric
8{
9 public override void AmendProject( IProjectAmender amender )
10 {
11 amender.SelectTypesDerivedFrom( typeof(TextReader) )
12 .MustRespectNamingConvention( "*Reader" );
13 }
14}
15
1using System.IO;
2
3namespace Doc.LAMA0906.Error;
4
5// The name of this class does not end with Reader.
Warning LAMA0906: The type 'TextLoader' does not respect the naming convention set by a fabric. The type name should match the "^.*Reader$" pattern.
6internal class TextLoader : TextReader { }
7
Resolution
Rename the declaration so that its name matches the pattern given in the message. If the declaration is a legitimate exception, change the query in the fabric so that it doesn't select this declaration, for instance with a Where clause.
In the following example, the class is renamed to TextFileReader.
1using Metalama.Extensions.Architecture;
2using Metalama.Framework.Fabrics;
3using System.IO;
4
5namespace Doc.LAMA0906.Fixed;
6
7internal class Fabric : ProjectFabric
8{
9 public override void AmendProject( IProjectAmender amender )
10 {
11 amender.SelectTypesDerivedFrom( typeof(TextReader) )
12 .MustRespectNamingConvention( "*Reader" );
13 }
14}
15
1using System.IO;
2
3namespace Doc.LAMA0906.Fixed;
4
5// The name of this class ends with Reader.
6internal class TextFileReader : TextReader { }
7