Coder Social home page Coder Social logo

tcartwright / sqlserver.rules Goto Github PK

View Code? Open in Web Editor NEW
38.0 38.0 10.0 592 KB

SQL Server static code analysis rules for SSDT database projects

License: MIT License

C# 95.03% XSLT 1.76% TSQL 2.31% PowerShell 0.81% Batchfile 0.09%
analysis sql-server static-analysis

sqlserver.rules's Introduction

Hi there πŸ‘‹

I am Tim Cartwright, a DBA / Developer from Houston Texas

  • πŸ”­ I’m currently working on the repos I maintain as well as my 9 to 5.
    • I tend to post a lot of loose sql files and powershell scripts to my GIST
  • I have a variety of interests:
    • SQL Server
      • Administration
      • T-SQL and DB Optimization
    • Application and Web development
    • Devops
    • Administrative scripts and tools
  • I am willing to collaborate on anything that piques my interest. Or accept collaboration on any of my repos. πŸ˜„

sqlserver.rules's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlserver.rules's Issues

Refactor docs generator to find .dll from csproj file

  • The documentation generator should not need the hardcoded path to the DLL file. The values are available from the csproj file.
  • Extend logging
  • Add table to Table of Contents: Friendly Name | Ignorable | Message
  • Modify docs generator script to take in the new $GITHUB_BUILD_OUTPUT_DLL variable and remove all hard coded references to "SQLServer.Rules.dll" or "SQLServer.Rules". Infer all those values from the path passed in.

Per project detailed documentation

Write detailed documentation for each project. Especially:

  • SqlServer.Rules.SolutionGenerator
    • Demo report(s)
  • SqlServer.Dac
  • SqlServer.Rules
    • will be partly handled by the MD generator script

Add XML Docs to Design Rule Classes (3)

Add to these files:

  • SqlServer.Rules/Design/DoNotMixDMLWithDDLRule.cs
  • SqlServer.Rules/Design/DeleteWithoutWhereRule.cs
  • SqlServer.Rules/Design/ConsiderEXISTSInsteadOfInRule.cs
  • SqlServer.Rules/Design/ConsiderColumnPrefixRule.cs
  • SqlServer.Rules/Design/CacheGetDateToVariable.cs
  • SqlServer.Rules/Design/AvoidWidePKsRule.cs
  • SqlServer.Rules/Design/AvoidViewJoinsRule.cs
  • SqlServer.Rules/Design/AvoidSetRowcountRule.cs
  • SqlServer.Rules/Design/AvoidSelectStarRule.cs
  • SqlServer.Rules/Design/AvoidSelectIntoRule.cs
  • SqlServer.Rules/Design/AvoidORInQueriesRule.cs
  • SqlServer.Rules/Design/AvoidNumericOrderByRule.cs
  • SqlServer.Rules/Design/AvoidIfInStoredProcRule.cs
  • SqlServer.Rules/Design/AvoidHintsRule.cs
  • SqlServer.Rules/Design/AvoidExecuteRule.cs
  • SqlServer.Rules/Design/AvoidCursorsRule.cs
  • SqlServer.Rules/Design/AvoidCHARTypeRule.cs
  • SqlServer.Rules/Design/AvoidCHARINDEXRule.cs
  • SqlServer.Rules/Design/AliasTablesRule.cs

Documenation builder

We can ticket out the work.

  • powershell to extract the MD from the C# attributes, and xml comments.

Pulls from:

  • Fill out summary tag
  • FriendlyName, and IsIgnorable tags
  • ExampleMd tag with good / bad examples

Originally posted by @tcartwright in #14 (comment)

Add XML Docs to the the Performance Class files (1)

Add docs the the following:

  • SqlServer.Rules/Performance/UseExistenceInsteadOfCountRule.cs
  • SqlServer.Rules/Performance/TableMissingClusteredIndexRule.cs
  • SqlServer.Rules/Performance/SetNoCountOnRule.cs
  • SqlServer.Rules/Performance/QueryHighJoinCountRule.cs
  • SqlServer.Rules/Performance/NestedViewRule.cs
  • SqlServer.Rules/Performance/ModifiedParameterRule.cs
  • SqlServer.Rules/Performance/DoNotUseDistinctInAggregatesRule.cs
  • SqlServer.Rules/Performance/DataTypesOnBothSidesOfEqualityRule.cs
  • SqlServer.Rules/Performance/CursorNotDeallocatedRule.cs
  • SqlServer.Rules/Performance/CursorNotClosedRule.cs
  • SqlServer.Rules/Performance/ConsiderRecompileQueryHintRule.cs
  • SqlServer.Rules/Performance/ConsiderIndexingInClauseColumnsRule.cs
  • SqlServer.Rules/Performance/AvoidUpdatingPrimaryKeyColumnsRule.cs
  • SqlServer.Rules/Performance/AvoidTableVariableInJoinsRule.cs
  • SqlServer.Rules/Performance/AvoidReturningResultsFromTriggersRule.cs
  • SqlServer.Rules/Performance/AvoidOuterJoinsRule.cs

Add XML Docs to Design Rule Classes (2)

Add doc comments to the following:

  • SqlServer.Rules/Design/ObjectUsesDifferentCollationRule.cs
  • SqlServer.Rules/Design/ObjectTwoPartNameRule.cs
  • SqlServer.Rules/Design/ObjectCreatedWithInvalidOptionsRule.cs
  • SqlServer.Rules/Design/NoPrecisionScaleRule.cs
  • SqlServer.Rules/Design/NoLengthVarcharRule.cs
  • SqlServer.Rules/Design/MissingJoinPredicateRule.cs
  • SqlServer.Rules/Design/MismatchedColumnsRule.cs
  • SqlServer.Rules/Design/InvalidDatabaseOptionsRule.cs
  • SqlServer.Rules/Design/HighNumberOfIndexesRule.cs
  • SqlServer.Rules/Design/FunctionTypeMismatchRule.cs
  • SqlServer.Rules/Design/ForeignKeysNeedIndexRule.cs
  • SqlServer.Rules/Design/EqualityCompareWithNULLRule.cs
  • SqlServer.Rules/Design/DuplicateIndexesRule.cs
  • SqlServer.Rules/Design/DoNotUseRealOrFloatRule.cs
  • SqlServer.Rules/Design/DoNotUseNOLOCKRule.cs
  • SqlServer.Rules/Design/DoNotUseIdentityFunction.cs
  • SqlServer.Rules/Design/DoNotUseDeprecatedTypesRule.cs

NEW RULE IDEAS

NEW RULE IDEAS

  • not for replication (Design) Added in rule SRD0065
  • Constraints: check for
    • udf usage (Performance)
    • nocheck (Design)
  • Suggest SCHEMABINDING for functions that do not touch tables (Performance)
  • Detect sql injection possibilities???

Notes:

  • Would like to only detect injection opportunies where sql is being concatenated in from a variable.
  • Would also like to build a sql injection scanner for .Net code

Add XML Docs to Design Rule Classes (1)

Add docs to the following:

  • SqlServer.Rules/Design/WrapStatementsWithTryCatchRule.cs
  • SqlServer.Rules/Design/WrapStatementsWithTransactionRule.cs
  • SqlServer.Rules/Design/WaitForRule.cs
  • SqlServer.Rules/Design/UseProperCollationInTempTables.cs
  • SqlServer.Rules/Design/UseParameterNamesWithProcsRule.cs
  • SqlServer.Rules/Design/UseColumnListWithInsertsRule.cs
  • SqlServer.Rules/Design/UpdateWithoutWhereRule.cs
  • SqlServer.Rules/Design/UnusedVariablesRule.cs
  • SqlServer.Rules/Design/UnusedParameterRule.cs
  • SqlServer.Rules/Design/TypesMissingParametersRule.cs
  • SqlServer.Rules/Design/TopWithoutOrderByRule.cs
  • SqlServer.Rules/Design/TableHasUniqueConstraintRule.cs
  • SqlServer.Rules/Design/TableHasPrimaryKeyRule.cs
  • SqlServer.Rules/Design/StartIdentity1000Rule.cs
  • SqlServer.Rules/Design/RaiseErrorWithoutLogRule.cs
  • SqlServer.Rules/Design/ProcedureContainsGrantRule.cs
  • SqlServer.Rules/Design/PredicateCompareRule.cs

Add XML Docs to the Performance Class files (2)

Add to these files:

  • SqlServer.Rules/Performance/AvoidNotInRule.cs
  • SqlServer.Rules/Performance/AvoidNotEqualToRule.cs
  • SqlServer.Rules/Performance/AvoidFunctionsInActionQueries.cs
  • SqlServer.Rules/Performance/AvoidEndsWithOrContainsRule.cs
  • SqlServer.Rules/Performance/AvoidCorrelatedSubqueriesRule.cs
  • SqlServer.Rules/Performance/AvoidColumnFunctionsRule.cs
  • SqlServer.Rules/Performance/AvoidColumnCalcsRule.cs

Add CI for

Just the basics for now:

  • branch per feature
  • gate accepting pull request with unit test

Add XML Docs to the Naming Rule Classes

Add docs the the following:

  • SqlServer.Rules/Naming/UseTwoPartNamesRule.cs
  • SqlServer.Rules/Naming/NamingViolationRule.cs
  • SqlServer.Rules/Naming/GeneralNamingRules.cs
  • SqlServer.Rules/Naming/AvoidSPPrefixRule.cs
  • SqlServer.Rules/Naming/AvoidFNPrefixRule.cs
  • SqlServer.Rules/NamedTableView.cs

Add XML Docs to core clas files

Add docs to the following:

  • SqlServer.Rules/SqlServerRule.cs
  • SqlServer.Rules/ReferentialIntegrity/RIUtils.cs
  • SqlServer.Rules/ReferentialIntegrity/JoinInfo.cs
  • SqlServer.Rules/ReferentialIntegrity/ForeignKeyInfo.cs
  • SqlServer.Rules/Globals/ModelInfo.cs
  • SqlServer.Rules/Globals/Ignorables.cs
  • SqlServer.Rules/Globals/Constants.cs
  • SqlServer.Rules/BaseSqlCodeAnalysisRule.cs

Rules don't evaluate on Visual Studio 2022

I was working with a customer that was trying to implement these rules with Visual Studio 2022. When done through the VS GUI the rules were successfully evaluated, but when done from msbuild.exe, the rules were essentially ignored. The problem was determined to be that the SqlServer.Rules solution was compiled with DacFx 150. It appears this causes issues with the Microsoft Entity Framework such that when MEF tries to match the rules with the required condition, it can’t match the types in 150 and 160. We downloaded the source code of the SqlServer.Rules and compiled it using DacFx 160 and were able to get Visual Studio 2022 to recognize the custom rules and evaluate them when run from msbuild.exe.

If you want to make these custom rules compatible with VS 2022, please rebuild the solution with DacFx 160. This should be backwards compatible such that the new release still works with previous Visual Studio version as well.

Please see microsoft/DacFx#364 for reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.