{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/3162","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/3162/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/3162/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/3162/events","html_url":"https://github.com/dotnet/roslyn/pull/3162","id":82173071,"number":3162,"title":"Add an analyzer to CodeAnalysis analyzers package that detects incorr…","user":{"login":"mavasani","id":10605811,"avatar_url":"https://avatars.githubusercontent.com/u/10605811?v=3","gravatar_id":"","url":"https://api.github.com/users/mavasani","html_url":"https://github.com/mavasani","followers_url":"https://api.github.com/users/mavasani/followers","following_url":"https://api.github.com/users/mavasani/following{/other_user}","gists_url":"https://api.github.com/users/mavasani/gists{/gist_id}","starred_url":"https://api.github.com/users/mavasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavasani/subscriptions","organizations_url":"https://api.github.com/users/mavasani/orgs","repos_url":"https://api.github.com/users/mavasani/repos","events_url":"https://api.github.com/users/mavasani/events{/privacy}","received_events_url":"https://api.github.com/users/mavasani/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Analyzers","name":"Area-Analyzers","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/cla-already-signed","name":"cla-already-signed","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-28T23:39:32Z","updated_at":"2015-05-28T23:42:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/3162","html_url":"https://github.com/dotnet/roslyn/pull/3162","diff_url":"https://github.com/dotnet/roslyn/pull/3162.diff","patch_url":"https://github.com/dotnet/roslyn/pull/3162.patch"},"body":"…ect action registrations for stateful analyzers.\r\n\r\nFixes #2949\r\n\r\nUser scenario: User writes an analyzer that either defines a CompilationStartAction or CodeBlockStartAction to perform stateful analysis on the compilation/code block.\r\nAn analyzer start action enables performing stateful analysis over a given code unit in a performant way. However, incorrect design for such analyzers can lead to memory leaks and non-performant analyzer execution. This analyzer flags these cases and provides following guidelines for writing such stateful analyzers:\r\n1. Define a new scope for the registered start action, possibly with a private nested type for analyzing each code unit.\r\n2. If required, define and intialize state object(s) in the start action within this scope.\r\n3. Register intermediate non-end actions in the start action, that depend upon and/or modify this state. You must register at least one such action. If there are no dependent intermediate actions for a start action, then the start action should be replaced by a corresponding non-start action. For example, a CodeBlockStartAction with no registered actions or only a registered CodeBlockEndAction should be replaced with a CodeBlockAction.\r\n4. If required, register an end action to report diagnostics based on the final state.\r\n\r\nFix description: We already have an analyzer flagging RegisterXXXAction invocations for other incorrect usages. This change adds 2 more rules to this analyzer to flag:\r\n1. Start analysis context objects with only a registered end action.\r\n2. Start analysis context objects with no registered nested actions.\r\n\r\nTesting: Added unit tests for this analyzer + manual testing. Verified existing tests pass.\r\n\r\n/cc @ManishJayaswal @srivatsn This is for 1.0 (stable)"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/106630126","html_url":"https://github.com/dotnet/roslyn/pull/3162#issuecomment-106630126","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/3162","id":106630126,"user":{"login":"mavasani","id":10605811,"avatar_url":"https://avatars.githubusercontent.com/u/10605811?v=3","gravatar_id":"","url":"https://api.github.com/users/mavasani","html_url":"https://github.com/mavasani","followers_url":"https://api.github.com/users/mavasani/followers","following_url":"https://api.github.com/users/mavasani/following{/other_user}","gists_url":"https://api.github.com/users/mavasani/gists{/gist_id}","starred_url":"https://api.github.com/users/mavasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavasani/subscriptions","organizations_url":"https://api.github.com/users/mavasani/orgs","repos_url":"https://api.github.com/users/mavasani/repos","events_url":"https://api.github.com/users/mavasani/events{/privacy}","received_events_url":"https://api.github.com/users/mavasani/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T23:42:08Z","updated_at":"2015-05-28T23:42:08Z","body":"@JohnHamby @tmeschter @heejaechang @shyamnamboodiripad @jmarolf can you please review?"}}