You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs
+87-2Lines changed: 87 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,14 +25,16 @@ public class NoXmlFileHeaderUnitTests : CodeFixVerifier
25
25
""copyrightText"": ""Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information."",
26
26
""variables"": {
27
27
""licenseName"": ""???"",
28
-
""licenseFile"": ""LICENSE"",
28
+
""licenseFile"": ""LICENSE""
29
29
},
30
30
""xmlHeader"": false
31
31
}
32
32
}
33
33
}
34
34
";
35
35
36
+
privatestringcurrentTestSettings=TestSettings;
37
+
36
38
/// <summary>
37
39
/// Verifies that the analyzer will report <see cref="FileHeaderAnalyzers.SA1633DescriptorMissing"/> for
38
40
/// projects not using XML headers when the file is completely missing a header.
@@ -48,6 +50,89 @@ public virtual async Task TestNoFileHeaderAsync()
48
50
varfixedCode=@"// Copyright (c) FooCorp. All rights reserved.
49
51
// Licensed under the ??? license. See LICENSE file in the project root for full license information.
""copyrightText"": ""{fileName} Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information."",
77
+
""variables"": {
78
+
""licenseName"": ""???"",
79
+
""licenseFile"": ""LICENSE""
80
+
},
81
+
""xmlHeader"": false
82
+
}
83
+
}
84
+
}
85
+
";
86
+
87
+
vartestCode=@"namespace Foo
88
+
{
89
+
}
90
+
";
91
+
varfixedCode=@"// Test0.cs Copyright (c) FooCorp. All rights reserved.
92
+
// Licensed under the ??? license. See LICENSE file in the project root for full license information.
""copyrightText"": ""{fileName} Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information."",
118
+
""variables"": {
119
+
""licenseName"": ""???"",
120
+
""licenseFile"": ""LICENSE"",
121
+
""fileName"": ""Not a file""
122
+
},
123
+
""xmlHeader"": false
124
+
}
125
+
}
126
+
}
127
+
";
128
+
129
+
vartestCode=@"namespace Foo
130
+
{
131
+
}
132
+
";
133
+
varfixedCode=@"// Not a file Copyright (c) FooCorp. All rights reserved.
134
+
// Licensed under the ??? license. See LICENSE file in the project root for full license information.
Copy file name to clipboardExpand all lines: documentation/Configuration.md
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -328,11 +328,16 @@ The following properties are used to configure copyright headers in StyleCop Ana
328
328
329
329
#### Configuring Copyright Text
330
330
331
-
In order to successfully use StyleCop-checked file headers, most projects will need to configure the `companyName` property.
331
+
In order to successfully use StyleCop-checked file headers, most projects will need to configure the `companyName`
332
+
property.
332
333
333
-
> The `companyName` property is so frequently customized that it is included in the default **stylecop.json** file produced by the code fix.
334
+
> The `companyName` property is so frequently customized that it is included in the default **stylecop.json** file
335
+
> produced by the code fix.
334
336
335
-
The `copyrightText` property is a string which may contain placeholders. Each placeholder has the form `{variable}`, where `variable` is either `companyName` or the name of a property in the `variables` property. The following sample file shows a custom **stylecop.json** file which references both `companyName` and two custom variables within the `copyrightText`.
337
+
The `copyrightText` property is a string which may contain placeholders. Each placeholder has the form `{variable}`,
338
+
where `variable` is either a built-in variable (see below), or the name of a property in the `variables` property. The
339
+
following sample file shows a custom **stylecop.json** file which references both `companyName` and two custom variables
340
+
within the `copyrightText`.
336
341
337
342
```json
338
343
{
@@ -358,6 +363,16 @@ With the above configuration, a file **TypeName.cs** would be expected to have t
358
363
// </copyright>
359
364
```
360
365
366
+
##### Built-In Variables
367
+
368
+
| Variable | Meaning |
369
+
| --- | --- |
370
+
|`companyName`| The value of the `companyName` configuration property in **stylecop.json**|
371
+
|`fileName`| The file name of the current source file |
372
+
373
+
> :memo: If a `fileName` variable is explicitly included within the `variables` property of **stylecop.json**, that
374
+
> value will be used instead of the name of the current source file.
375
+
361
376
#### Configuring XML Headers
362
377
363
378
When the `xmlHeader` property is **true** (the default), StyleCop Analyzers expects file headers to conform to the following standard StyleCop format.
0 commit comments