Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ The list of plugins must be specified in the [configuration file](./TeamTools.Li
## Parameters

| Parameter | Shortcut | Description |
|-----------|---------|-------------|
|-----------|----------|-------------|
| `--evaluate` | — | Evaluate mode to test linter features. It uses severity = warning and EvaluateConfig.json |
| `--config` | `-c` | Path to the configuration file |
| `--dir` | `-d` | Path to a directory containing files to be linted |
| `--file` | `-f` | Path to a single file to be linted |
Expand All @@ -26,14 +27,25 @@ The list of plugins must be specified in the [configuration file](./TeamTools.Li
| `--severity` | `-s` | Minimum severity level of findings to include in results. Default is `info` (includes all errors, warnings, hints, and info messages). Use `warning` to include only errors and warnings, or `error` for only explicit errors. Severity levels for each rule are defined in the plugin configuration |
| `--basepath` | `-r` | Base path for files. If specified, relative paths (with this base) will be used in logs and output instead of absolute paths |
| `--verbose` | `-v` | Print detailed progress information to the console |
| `--withversion` | `-n` | Print the version number before outputting results. Unlike `--version`, this allows linting to proceed while also showing the current version in the log |
| `--with-version` | `-n` | Print the version number before outputting results. Unlike `--version`, this allows linting to proceed while also showing the current version in the log |
| `--diff` | — | Lint all files differing from the `master` branch. Works only when running on files in a Git repository (Git must be in `PATH`). Alternatively, compute the file list manually, save it to a text file, and pass its path via `--filelist` |
| `--quiet` | — | Do not return a non‑zero exit code if linting findings are detected |
| `--version` | — | Print the utility version without performing other operations |
| `--help` | — | Display the list of parameters |

## Usage Examples

### 🚀 First time run to evaluate linter features and capabilities

```cmd
.\TeamTools.Linter.CommandLine.exe --dir "c:\source\my_project" --evaluate
```

Evaluate-mode raises minimal severity to `warning` and forces `EvaluateConfig.json` to be used.
Use this mode to find significant violations in a project which has never been analyzed by this linter before
to test if the linter suffices your needs. Rules related to formatting standard, naming convention and such
are disabled in this mode.

### Linting diff for a directory

```cmd
Expand All @@ -48,7 +60,7 @@ The diff is calculated via Git against the main branch; only modified files are
.\TeamTools.Linter.CommandLine.exe --file "c:\source\my_project\Stored procedures\dbo.my_proc.sql"
```

### Linting all files in a directory and excluding info messages
### Linting all files in a directory excluding info messages

```cmd
.\TeamTools.Linter.CommandLine.exe --dir "c:\source\my_project" --severity warning
Expand Down
18 changes: 18 additions & 0 deletions TeamTools.Linter.CommandLine/Config/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace TeamTools.TSQL.Linter.CommandLine.Config
public class CommandLineOptions
{
private string configFile = SanitizePath(Path.Combine(AppContext.BaseDirectory, "DefaultConfig.json"));
private string evaluateConfigFile = SanitizePath(Path.Combine(AppContext.BaseDirectory, "EvaluateConfig.json"));
private string directoryName;
private string fileName;
private string fileListSource;
Expand Down Expand Up @@ -250,6 +251,23 @@ public string BasePath
HelpText = "Show current version")]
public bool Version { get; set; }

[Option(
longName: "evaluate",
Required = false,
Default = false,
HelpText = "Use this option for first run to detect significant violations only")]
public bool EvaluateApp
{
set
{
if (value)
{
minimalSeverity = Severity.Warning;
configFile = evaluateConfigFile;
}
}
}

private static string SanitizePath(string value)
{
if (string.IsNullOrWhiteSpace(value))
Expand Down
43 changes: 43 additions & 0 deletions TeamTools.Linter.CommandLine/EvaluateConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"plugins": {
"SSDT": {
"dll": "./Plugins/TeamTools.Linter.SSDT/TeamTools.SSDT.ProjectValidator.dll",
"config": "./Plugins/TeamTools.Linter.SSDT/DefaultConfig.json"
},
"TSQL": {
"dll": "./Plugins/TeamTools.Linter.TSQL/TeamTools.TSQL.Linter.dll",
"config": "./Plugins/TeamTools.Linter.TSQL/EvaluateConfig.json"
}
},
"ignore": {
"folders": [
".git",
".vs",
".stylecop",
"bin",
"obj",
"Framework",
"TestResults",
"TestSources",
"node_packages",
"packages",
"tSQLt"
],
"extensions": [
".dll",
".orig",
".exe",
".user",
".local",
".dbmdl",
".jfm",
".dacpac",
".rar",
".zip",
".7z"
]
},
"options": {
"mainBranch": "master"
}
}
15 changes: 4 additions & 11 deletions TeamTools.Linter.CommandLine/TeamTools.Linter.CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
<ItemGroup>
<Content Include="..\LICENSE" Pack="true" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DefaultConfig.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="EvaluateConfig.json" CopyToOutputDirectory="PreserveNewest" />
<Folder Include="plugins\" />
</ItemGroup>

<!-- Stuff for embedding plugin binaries into the build output -->
<PropertyGroup>
<SqlLinterProj>TeamTools.TSQL.Linter</SqlLinterProj>
<FileLinterProj>TeamTools.StructuredFiles.Linter</FileLinterProj>
<SsdtLinterProj>TeamTools.SSDT.ProjectValidator</SsdtLinterProj>
<SqlLinterProj>TeamTools.Linter.TSQL</SqlLinterProj>
<SsdtLinterProj>TeamTools.Linter.SSDT</SsdtLinterProj>

<PluginsPath>$(MSBuildThisFileDirectory)..</PluginsPath>
<PluginsPath>$(MSBuildThisFileDirectory)..\..</PluginsPath>
<PluginSourceSubfolder Condition="'$(TargetFramework)'=='netcoreapp3.1'">bin\$(Configuration)\netstandard2.0</PluginSourceSubfolder>
<PluginSourceSubfolder Condition="'$(TargetFramework)'!='netcoreapp3.1'">bin\$(Configuration)\$(TargetFramework)</PluginSourceSubfolder>
<PluginNugetTargetSubfolder>tools\$(TargetFramework)\any\plugins</PluginNugetTargetSubfolder>
Expand All @@ -54,9 +54,6 @@
<SqlLinterBin Include="$(PluginsPath)\$(SqlLinterProj)\$(PluginSourceSubfolder)\**\*.*">
<InProject>false</InProject>
</SqlLinterBin>
<FileLinterBin Include="$(PluginsPath)\$(FileLinterProj)\$(PluginSourceSubfolder)\**\*.*">
<InProject>false</InProject>
</FileLinterBin>
<SsdtLinterBin Include="$(PluginsPath)\$(SsdtLinterProj)\$(PluginSourceSubfolder)\**\*.*">
<InProject>false</InProject>
</SsdtLinterBin>
Expand All @@ -79,7 +76,6 @@

<Target Name="CopyPlugins" AfterTargets="AfterBuild">
<Copy SourceFiles="@(SqlLinterBin)" DestinationFiles="$(TargetDir)\plugins\$(SqlLinterProj)\%(RecursiveDir)%(FileName)%(Extension)" />
<Copy SourceFiles="@(FileLinterBin)" DestinationFiles="$(TargetDir)\plugins\$(FileLinterProj)\%(RecursiveDir)%(FileName)%(Extension)" />
<Copy SourceFiles="@(SsdtLinterBin)" DestinationFiles="$(TargetDir)\plugins\$(SsdtLinterProj)\%(RecursiveDir)%(FileName)%(Extension)" />
</Target>

Expand All @@ -91,9 +87,6 @@
<TfmSpecificPackageFile Include="@(SsdtLinterBin)">
<PackagePath>$(PluginNugetTargetSubfolder)\$(SsdtLinterProj)\%(RecursiveDir)%(FileName)%(Extension)</PackagePath>
</TfmSpecificPackageFile>
<TfmSpecificPackageFile Include="@(FileLinterBin)">
<PackagePath>$(PluginNugetTargetSubfolder)\$(FileLinterProj)\%(RecursiveDir)%(FileName)%(Extension)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace TeamTools.TSQL.Linter.CommandLineTests
[Category("Linter.ConsoleExe")]
public class CommandLineOptionsTests
{
private Dictionary<string, List<string>> argVariants;
#if Windows
private const string BasePath = @"c:\";
#else
private const string BasePath = @"/home/";
#endif

private Dictionary<string, List<string>> argVariants;

[SetUp]
public void Setup()
{
Expand Down
10 changes: 8 additions & 2 deletions cli-linter.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Nuget.Config": "xml"
},
"[xml]": {
"editor.tabSize": 2
"editor.tabSize": 2,
"editor.wordWrap": "off"
},
"editor.insertSpaces": true,
"editor.formatOnSave": true,
Expand All @@ -39,6 +40,10 @@
"editor.suggest.insertMode": "replace",
"editor.defaultFormatter": "vscode.json-language-features"
},
"[code-workspace]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"markdownlint.config": {
"MD033": {
"allowed_elements": ["p"],
Expand Down Expand Up @@ -134,7 +139,8 @@
// To prevent weird values from local computer environment variables.
// This will be converted into "Any CPU" by Directory.Build.props
"PLATFORM": ""
}
},
"xml.format.maxLineWidth": 0
},
"extensions": {
"recommendations": [
Expand Down
Loading