OSDN Git Service

不要な変数への代入を削除 (IDE0058, IDE0059)
authorKimura Youichi <kim.upsilon@bucyou.net>
Wed, 28 Aug 2019 17:38:48 +0000 (02:38 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 28 Aug 2019 19:26:38 +0000 (04:26 +0900)
14 files changed:
OpenTween.Tests/LRUCacheDictionaryTest.cs
OpenTween.Tests/Models/TabInformationTest.cs
OpenTween.Tests/TwitterTest.cs
OpenTween/FilterDialog.cs
OpenTween/Growl.cs
OpenTween/HashtagManage.cs
OpenTween/Models/HomeTabModel.cs
OpenTween/Models/InternalStorageTabModel.cs
OpenTween/Models/TabInformations.cs
OpenTween/NativeMethods.cs
OpenTween/Thumbnail/Services/Tumblr.cs
OpenTween/Tween.cs
OpenTween/Twitter.cs
OpenTween/UserInfoDialog.cs

index 7bfa148..2114d97 100644 (file)
@@ -51,9 +51,9 @@ namespace OpenTween
             Assert.Equal("key1", node.Value.Key);
 
             // 2 -> 3 -> 1 の順に値を参照
-            var x = dict["key2"];
-            x = dict["key3"];
-            x = dict["key1"];
+            _ = dict["key2"];
+            _ = dict["key3"];
+            _ = dict["key1"];
 
             // 直近に参照した順で並んでいるかテスト
             node = dict.innerList.First;
@@ -108,11 +108,11 @@ namespace OpenTween
             };
 
             // 4 -> 2 -> 3 -> 1 -> 5 の順で参照
-            var x = dict["key4"];
-            x = dict["key2"];
-            x = dict["key3"];
-            x = dict["key1"];
-            x = dict["key5"];
+            _ = dict["key4"];
+            _ = dict["key2"];
+            _ = dict["key3"];
+            _ = dict["key1"];
+            _ = dict["key5"];
 
             // 3 個までに縮小
             dict.TrimLimit = 3;
@@ -144,8 +144,8 @@ namespace OpenTween
 
             dict["key5"] = "value5";         // 5アクセス目
             dict.Add("key6", "value6");      // 6アクセス目
-            var x = dict["key2"];            // 7アクセス目
-            dict.TryGetValue("key4", out x); // 8アクセス目 (この直後にTrim)
+            _ = dict["key2"];                // 7アクセス目
+            dict.TryGetValue("key4", out _); // 8アクセス目 (この直後にTrim)
 
             // 5 -> 6 -> 2 -> 4 の順でアクセスしたため、直近 3 件の 6, 2, 4 だけが残る
             Assert.Equal(new[] { "key6", "key2", "key4" }, dict.innerDict.Keys, collComparer);
index 598855b..c6300c8 100644 (file)
@@ -416,8 +416,7 @@ namespace OpenTween.Models
             // この時点ではまだ削除されない
             Assert.Equal(1, homeTab.AllCount);
 
-            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts,
-                out var newMentionOrDm, out var isDeletePost);
+            this.tabinfo.SubmitUpdate(out _, out _, out _, out var isDeletePost);
 
             Assert.True(isDeletePost);
             Assert.Equal(0, homeTab.AllCount);
@@ -444,8 +443,7 @@ namespace OpenTween.Models
             Assert.Equal(1, homeTab.AllCount);
             Assert.Equal(1, favTab.AllCount);
 
-            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts,
-                out var newMentionOrDm, out var isDeletePost);
+            this.tabinfo.SubmitUpdate(out _, out _, out _, out var isDeletePost);
 
             Assert.True(isDeletePost);
             Assert.Equal(1, homeTab.AllCount);
@@ -481,8 +479,7 @@ namespace OpenTween.Models
 
             this.tabinfo.DistributePosts();
 
-            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts,
-                out var newMentionOrDm, out var isDeletePost);
+            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts, out _, out _);
 
             // DM が最も優先度が高いため DM の通知音が再生される
             Assert.Equal("dm.wav", soundFile);
@@ -510,8 +507,7 @@ namespace OpenTween.Models
 
             this.tabinfo.DistributePosts();
 
-            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts,
-                out var newMentionOrDm, out var isDeletePost);
+            this.tabinfo.SubmitUpdate(out var soundFile, out var notifyPosts, out _, out _);
 
             // リプライの方が通知音の優先度が高いが、replyTab.SoundFile が空文字列なので次点の Recent の通知音を鳴らす
             Assert.Equal("home.wav", soundFile);
index 77edce9..fa9550c 100644 (file)
@@ -292,18 +292,6 @@ namespace OpenTween
         {
             var text = "hoge";
             var entities = new TwitterEntities();
-            var quotedStatus = new TwitterStatus
-            {
-                Id = 1234567890L,
-                IdStr = "1234567890",
-                User = new TwitterUser
-                {
-                    Id = 1111,
-                    IdStr = "1111",
-                    ScreenName = "foo",
-                },
-                FullText = "test",
-            };
             var quotedStatusLink = new TwitterQuotedStatusPermalink
             {
                 Url = "https://t.co/hoge",
index b755e5f..fe9c07b 100644 (file)
@@ -1067,7 +1067,7 @@ namespace OpenTween
             if (ListTabs.SelectedIndex > -1)
             {
                 var origTabName = this.SelectedTab.TabName;
-                if (((TweenMain)this.Owner).TabRename(origTabName, out var _))
+                if (((TweenMain)this.Owner).TabRename(origTabName, out _))
                     this.RefreshListTabs();
             }
         }
@@ -1342,7 +1342,6 @@ namespace OpenTween
                 if (tbox.SelectionStart > 0)
                 {
                     var endidx = tbox.SelectionStart - 1;
-                    var startstr = "";
                     for (var i = tbox.SelectionStart - 1; i >= 0; i--)
                     {
                         var c = tbox.Text[i];
@@ -1350,6 +1349,7 @@ namespace OpenTween
                         {
                             continue;
                         }
+                        string startstr;
                         if (c == '@')
                         {
                             startstr = tbox.Text.Substring(i + 1, endidx - i);
index f1bff9a..5643a54 100644 (file)
@@ -277,11 +277,11 @@ namespace OpenTween
                     notificationName = "USERSTREAM_EVENT";
                     break;
             }
-            object n = null;
+            object n;
             if (icon != null || !string.IsNullOrEmpty(url))
             {
                 var gCore = _core.GetType("Growl.CoreLibrary.Resource");
-                object res = null;
+                object res;
                 if (icon != null)
                 {
                     res = gCore.InvokeMember("op_Implicit",
index 35bc568..814968e 100644 (file)
@@ -296,10 +296,9 @@ namespace OpenTween
             if (!this.AdjustHashtags(ref hashStr, !this.RunSilent)) return;
 
             UseHashText.Text = hashStr;
-            var idx = 0;
             if (!this._isAdd && this.HistoryHashList.SelectedIndices.Count > 0)
             {
-                idx = this.HistoryHashList.SelectedIndices[0];
+                var idx = this.HistoryHashList.SelectedIndices[0];
                 this.HistoryHashList.Items.RemoveAt(idx);
                 do
                 {
index 98680df..98a599e 100644 (file)
@@ -109,7 +109,7 @@ namespace OpenTween.Models
             Interlocked.Exchange(ref this.tweetsPerHour, tweetsInWindow);
 
             foreach (var key in removeKeys)
-                this.tweetsTimestamps.TryRemove(key, out var _);
+                this.tweetsTimestamps.TryRemove(key, out _);
         }
     }
 }
index edff353..47f206c 100644 (file)
@@ -71,7 +71,7 @@ namespace OpenTween.Models
             if (!base.RemovePostImmediately(statusId))
                 return false;
 
-            this.internalPosts.TryRemove(statusId, out var removedPost);
+            this.internalPosts.TryRemove(statusId, out _);
 
             return true;
         }
index 21e1477..cb97fc9 100644 (file)
@@ -348,7 +348,7 @@ namespace OpenTween.Models
         }
 
         public int SubmitUpdate()
-            => this.SubmitUpdate(out var soundFile, out var notifyPosts, out var newMentionOrDm, out var isDeletePost);
+            => this.SubmitUpdate(out _, out _, out _, out _);
 
         public int SubmitUpdate(out string soundFile, out PostClass[] notifyPosts,
             out bool newMentionOrDm, out bool isDeletePost)
index bdf088b..a6523e3 100644 (file)
@@ -290,7 +290,6 @@ namespace OpenTween
                 UnregisterHotKey(targetForm.Handle, hotkeyID);
                 // clean up the atom list
                 GlobalDeleteAtom(hotkeyID);
-                hotkeyID = 0;
             }
         }
         #endregion
index d11ce93..9e60fca 100644 (file)
@@ -68,7 +68,7 @@ namespace OpenTween.Thumbnail.Services
             var param = new Dictionary<string, string>
             {
                 ["api_key"] = ApplicationSettings.TumblrConsumerKey,
-                ["id"] = match.Groups["postId"].Value,
+                ["id"] = postId,
             };
 
             try
index 80366ad..4d8011e 100644 (file)
@@ -3020,7 +3020,7 @@ namespace OpenTween
             var listCache = this._listItemCache;
             if (listCache != null)
             {
-                if (listCache.TryGetValue(Index, out var item, out var post))
+                if (listCache.TryGetValue(Index, out _, out var post))
                     return post;
             }
 
@@ -4566,7 +4566,7 @@ namespace OpenTween
         }
 
         private string FormatStatusTextExtended(string statusText)
-            => this.FormatStatusTextExtended(statusText, out var autoPopulatedUserIds, out var attachmentUrl);
+            => this.FormatStatusTextExtended(statusText, out _, out _);
 
         /// <summary>
         /// <see cref="FormatStatusText"/> に加えて、拡張モードで140字にカウントされない文字列の除去を行います
@@ -4716,7 +4716,7 @@ namespace OpenTween
             var listCache = this._listItemCache;
             if (listCache?.TargetList == sender)
             {
-                if (listCache.TryGetValue(e.ItemIndex, out var item, out var cacheItemPost))
+                if (listCache.TryGetValue(e.ItemIndex, out var item, out _))
                 {
                     e.Item = item;
                     return;
@@ -4874,7 +4874,7 @@ namespace OpenTween
             if (e.State == 0) return;
             e.DrawDefault = false;
 
-            SolidBrush brs2 = null;
+            SolidBrush brs2;
             if (!e.Item.Selected)     //e.ItemStateでうまく判定できない???
             {
                 if (e.Item.BackColor == _clSelf)
@@ -6246,7 +6246,6 @@ namespace OpenTween
 
         private void CopyStot()
         {
-            var clstr = "";
             var sb = new StringBuilder();
             var tab = this.CurrentTab;
             var IsProtected = false;
@@ -6272,7 +6271,7 @@ namespace OpenTween
             }
             if (sb.Length > 0)
             {
-                clstr = sb.ToString();
+                var clstr = sb.ToString();
                 try
                 {
                     Clipboard.SetDataObject(clstr, false, 5, 100);
@@ -6315,9 +6314,9 @@ namespace OpenTween
 
             var selectedIndex = tab.SelectedIndex;
 
-            var fIdx = 0;
-            var toIdx = 0;
-            var stp = 1;
+            int fIdx;
+            int toIdx;
+            int stp;
 
             if (forward)
             {
@@ -6328,7 +6327,8 @@ namespace OpenTween
                 else
                 {
                     fIdx = selectedIndex + 1;
-                    if (fIdx > tab.AllCount - 1) return;
+                    if (fIdx > tab.AllCount - 1)
+                        return;
                 }
                 toIdx = tab.AllCount;
                 stp = 1;
@@ -6342,7 +6342,8 @@ namespace OpenTween
                 else
                 {
                     fIdx = selectedIndex - 1;
-                    if (fIdx < 0) return;
+                    if (fIdx < 0)
+                        return;
                 }
                 toIdx = -1;
                 stp = -1;
@@ -6450,7 +6451,7 @@ namespace OpenTween
                 stp = -1;
             }
 
-            var name = "";
+            string name;
             if (currentPost.RetweetedId == null)
             {
                 name = currentPost.ScreenName;
@@ -7342,7 +7343,7 @@ namespace OpenTween
         }
 
         private void ListTab_DoubleClick(object sender, MouseEventArgs e)
-            => this.TabRename(this.CurrentTabName, out var _);
+            => this.TabRename(this.CurrentTabName, out _);
 
         private void ListTab_MouseDown(object sender, MouseEventArgs e)
         {
@@ -9022,10 +9023,9 @@ namespace OpenTween
             //Appendix A.  Collected ABNF for URI
             //http://www.ietf.org/rfc/rfc3986.txt
 
-            var result = "";
-
             const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
 
+            string result;
             if (StatusText.SelectionLength > 0)
             {
                 var tmp = StatusText.SelectedText;
@@ -9100,9 +9100,11 @@ namespace OpenTween
                 // 正規表現にマッチしたURL文字列をtinyurl化
                 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
                 {
-                    if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
+                    if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1)
+                        continue;
                     var tmp = mt.Result("${url}");
-                    if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
+                    if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase))
+                        tmp = "http://" + tmp;
                     var undotmp = new urlUndo();
 
                     //選んだURLを選択(?)
@@ -9204,8 +9206,9 @@ namespace OpenTween
         {
             if (!await UrlConvertAsync(SettingManager.Common.AutoShortUrlFirst))
             {
-                var svc = SettingManager.Common.AutoShortUrlFirst;
                 var rnd = new Random();
+
+                MyCommon.UrlConverter svc;
                 // 前回使用した短縮URLサービス以外を選択する
                 do
                 {
@@ -9527,8 +9530,7 @@ namespace OpenTween
 
         public bool IsNetworkAvailable()
         {
-            var nw = true;
-            nw = MyCommon.IsNetworkAvailable();
+            var nw = MyCommon.IsNetworkAvailable();
             _myStatusOnline = nw;
             return nw;
         }
@@ -10034,7 +10036,7 @@ namespace OpenTween
         {
             if (string.IsNullOrEmpty(_rclickTabName)) return;
 
-            TabRename(_rclickTabName, out var _);
+            _ = TabRename(_rclickTabName, out _);
         }
 
         private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
@@ -10208,7 +10210,7 @@ namespace OpenTween
                     return;
             }
 
-            var result = "";
+            string result;
             if (isFollowing)
             {
                 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
@@ -10460,9 +10462,8 @@ namespace OpenTween
             }
             else
             {
-                DetailsListView listView = null;
-
                 var tb = _statuses.RemovedTab.Pop();
+                DetailsListView listView;
                 if (tb.TabType == MyCommon.TabUsageType.Related)
                 {
                     var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
@@ -10485,7 +10486,8 @@ namespace OpenTween
                         var renamed = TabName;
                         for (var i = 2; i <= 100; i++)
                         {
-                            if (!_statuses.ContainsTab(renamed)) break;
+                            if (!_statuses.ContainsTab(renamed))
+                                break;
                             renamed = TabName + i;
                         }
                         tb.TabName = renamed;
@@ -10505,7 +10507,8 @@ namespace OpenTween
                     var renamed = tb.TabName;
                     for (var i = 1; i < int.MaxValue; i++)
                     {
-                        if (!_statuses.ContainsTab(renamed)) break;
+                        if (!_statuses.ContainsTab(renamed))
+                            break;
                         renamed = tb.TabName + "(" + i + ")";
                     }
                     tb.TabName = renamed;
@@ -10586,7 +10589,7 @@ namespace OpenTween
 
         private void HashManageMenuItem_Click(object sender, EventArgs e)
         {
-            var rslt = DialogResult.Cancel;
+            DialogResult rslt;
             try
             {
                 rslt = HashMgr.ShowDialog();
index 53ac9f9..485d61f 100644 (file)
@@ -239,12 +239,11 @@ namespace OpenTween
             {
                 if (orgData.IndexOf(href, posl2, StringComparison.Ordinal) > -1)
                 {
-                    var urlStr = "";
                     // IDN展開
                     posl1 = orgData.IndexOf(href, posl2, StringComparison.Ordinal);
                     posl1 += href.Length;
                     posl2 = orgData.IndexOf("\"", posl1, StringComparison.Ordinal);
-                    urlStr = orgData.Substring(posl1, posl2 - posl1);
+                    var urlStr = orgData.Substring(posl1, posl2 - posl1);
 
                     if (!urlStr.StartsWith("http://", StringComparison.Ordinal)
                         && !urlStr.StartsWith("https://", StringComparison.Ordinal)
index 106b60c..b266814 100644 (file)
@@ -67,10 +67,10 @@ namespace OpenTween
         [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]
         private void CancelLoading()
         {
-            CancellationTokenSource newTokenSource = null, oldTokenSource = null;
+            CancellationTokenSource oldTokenSource = null;
             try
             {
-                newTokenSource = new CancellationTokenSource();
+                var newTokenSource = new CancellationTokenSource();
                 oldTokenSource = Interlocked.Exchange(ref this.cancellationTokenSource, newTokenSource);
             }
             finally