コード例 #1
0
        public void ToString_ReturnsExpected()
        {
            const string input = "xxx:YYY";

            SonarCompositeRuleId.TryParse(input, out var output);
            output.ToString().Should().Be(input);
        }
コード例 #2
0
 public void TryParse_Valid_ReturnExpecteed(string errorCode, string expectedRepo, string expectedRule)
 {
     SonarCompositeRuleId.TryParse(errorCode, out var result).Should().BeTrue();
     result.ErrorListErrorCode.Should().Be(errorCode);
     result.RepoKey.Should().Be(expectedRepo);
     result.RuleKey.Should().Be(expectedRule);
 }
コード例 #3
0
        /// <summary>
        /// Returns the error code if:
        /// 1) there is only one selected error in the error list and
        /// 2) it is a SonarLint error
        /// </summary>
        internal /* for testing */ static bool TryGetRuleId(IErrorList errorList, out SonarCompositeRuleId ruleId)
        {
            ruleId = null;
            var selectedItems = errorList?.TableControl?.SelectedEntries;

            if (selectedItems?.Count() == 1)
            {
                var handle    = selectedItems.First();
                var errorCode = FindErrorCodeForEntry(handle);
                SonarCompositeRuleId.TryParse(errorCode, out ruleId);
            }

            return(ruleId != null);
        }
コード例 #4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            SonarCompositeRuleId ruleId = null;

            try
            {
                if (TryGetRuleId(errorList, out ruleId))
                {
                    userSettingsProvider.DisableRule(ruleId.ErrorListErrorCode);
                    logger.WriteLine(AnalysisStrings.DisableRule_DisabledRule, ruleId.ErrorListErrorCode);
                }

                Debug.Assert(ruleId != null, "Not expecting Execute to be called if the SonarLint error code cannot be determined");
            }
            catch (Exception ex) when(!Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex))
            {
                logger.WriteLine(AnalysisStrings.DisableRule_ErrorDisablingRule, ruleId?.ErrorListErrorCode ?? AnalysisStrings.DisableRule_UnknownErrorCode, ex.Message);
            }
        }
コード例 #5
0
        private static void CalculateStatuses(SonarCompositeRuleId rule, SonarLintMode mode, out bool isVisible, out bool isEnabled)
        {
            // Special case: JavaScript
            // We don't support connected mode for JavaScript at the moment so we allow disabling
            // in connected mode for now. See #770.
            if (SonarRuleRepoKeys.AreEqual(SonarRuleRepoKeys.JavaScript, rule.RepoKey))
            {
                isVisible = true;
                isEnabled = true;
                return;
            }

            // We don't currently support disabling rules for all repos
            if (supportedRepos.Contains(rule.RepoKey, SonarRuleRepoKeys.RepoKeyComparer))
            {
                isVisible = true;
                isEnabled = mode == SonarLintMode.Standalone;
                return;
            }

            isVisible = false;
            isEnabled = false;
        }
コード例 #6
0
 public void TryParse_Invalid_ReturnsNull(string errorCode)
 {
     SonarCompositeRuleId.TryParse(errorCode, out var result).Should().BeFalse();
     result.Should().BeNull();
 }