{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/5975","repository_url":"https://api.github.com/repos/eslint/eslint","labels_url":"https://api.github.com/repos/eslint/eslint/issues/5975/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/5975/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/5975/events","html_url":"https://github.com/eslint/eslint/issues/5975","id":151255457,"number":5975,"title":"curly: Allow to filter affected keywords and pass keywords-exceptions","user":{"login":"zxqfox","id":677518,"avatar_url":"https://avatars3.githubusercontent.com/u/677518?v=4","gravatar_id":"","url":"https://api.github.com/users/zxqfox","html_url":"https://github.com/zxqfox","followers_url":"https://api.github.com/users/zxqfox/followers","following_url":"https://api.github.com/users/zxqfox/following{/other_user}","gists_url":"https://api.github.com/users/zxqfox/gists{/gist_id}","starred_url":"https://api.github.com/users/zxqfox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zxqfox/subscriptions","organizations_url":"https://api.github.com/users/zxqfox/orgs","repos_url":"https://api.github.com/users/zxqfox/repos","events_url":"https://api.github.com/users/zxqfox/events{/privacy}","received_events_url":"https://api.github.com/users/zxqfox/received_events","type":"User","site_admin":false},"labels":[{"id":131106229,"url":"https://api.github.com/repos/eslint/eslint/labels/accepted","name":"accepted","color":"0052cc","default":false},{"id":45711352,"url":"https://api.github.com/repos/eslint/eslint/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":258830633,"url":"https://api.github.com/repos/eslint/eslint/labels/help%20wanted","name":"help wanted","color":"eb6420","default":true},{"id":45798639,"url":"https://api.github.com/repos/eslint/eslint/labels/rule","name":"rule","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/eslint/eslint/milestones/15","html_url":"https://github.com/eslint/eslint/milestone/15","labels_url":"https://api.github.com/repos/eslint/eslint/milestones/15/labels","id":1707375,"number":15,"title":"JSCS Compatibility","description":"","creator":{"login":"nzakas","id":38546,"avatar_url":"https://avatars3.githubusercontent.com/u/38546?v=4","gravatar_id":"","url":"https://api.github.com/users/nzakas","html_url":"https://github.com/nzakas","followers_url":"https://api.github.com/users/nzakas/followers","following_url":"https://api.github.com/users/nzakas/following{/other_user}","gists_url":"https://api.github.com/users/nzakas/gists{/gist_id}","starred_url":"https://api.github.com/users/nzakas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzakas/subscriptions","organizations_url":"https://api.github.com/users/nzakas/orgs","repos_url":"https://api.github.com/users/nzakas/repos","events_url":"https://api.github.com/users/nzakas/events{/privacy}","received_events_url":"https://api.github.com/users/nzakas/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":39,"state":"open","created_at":"2016-04-14T18:09:38Z","updated_at":"2017-06-22T03:20:23Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-04-26T22:35:28Z","updated_at":"2017-07-17T21:14:00Z","closed_at":null,"body":"JSCS has rules `disallowCurlyBraces` and `requireCurlyBraces` that allows to pass keywords: `[\"if\", \"else\", \"for\", \"while\", \"do\", \"try\", \"catch\", \"default\"]`.\n\nMore over `requireCurlyBraces` has `allExcept` option that works like exception for passed keywords:\n\n```\n    - `'allExcept'`\n        - Array of keywords inside of the block that would allow curly braces\n        - Ex: [\"return\" , \"continue\", \"break\"]\n```\n\nE.g. for:\n\n``` js\n\"allExcept\": [\"return\", \"continue\", \"break\"]\n```\n\nit works like:\n\n``` js\n// Here we need curlies\nif (true) {\n  // Dummy\n} else {\n  // Another one\n}\n\n// And here we don't\nif (true) return false;\nelse if (false) break;\nelse continue;\n```\n\nThe current `curly` options and the first suggestion:\n\n```\n\"curly\": [2, \"all\"]\n\"curly\": [2, \"multi\"]\n\"curly\": [2, \"multi-line\"]\n\"curly\": [2, \"multi-or-nest\"]\n\"curly\": [2, \"multi\", \"consistent\"]\n```\n\nI suggest to pass an `Object` with keywords and exceptions as the last parameter:\n\n```\n\"curly\": [2, { \"keywords\": [\"if\", \"else\"], \"except\": [\"return\", \"break\"] }]\n\"curly\": [2, \"multi\", { \"keywords\": … }]\n// or even:\n\"curly\": [2, { \"schema\": \"multi\", \"consistent\": true, \"keywords\": … }]\n```\n\nRelated: https://github.com/eslint/eslint/issues/4007\n"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/315886673","html_url":"https://github.com/eslint/eslint/issues/5975#issuecomment-315886673","issue_url":"https://api.github.com/repos/eslint/eslint/issues/5975","id":315886673,"user":{"login":"cbargren","id":1050712,"avatar_url":"https://avatars3.githubusercontent.com/u/1050712?v=4","gravatar_id":"","url":"https://api.github.com/users/cbargren","html_url":"https://github.com/cbargren","followers_url":"https://api.github.com/users/cbargren/followers","following_url":"https://api.github.com/users/cbargren/following{/other_user}","gists_url":"https://api.github.com/users/cbargren/gists{/gist_id}","starred_url":"https://api.github.com/users/cbargren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbargren/subscriptions","organizations_url":"https://api.github.com/users/cbargren/orgs","repos_url":"https://api.github.com/users/cbargren/repos","events_url":"https://api.github.com/users/cbargren/events{/privacy}","received_events_url":"https://api.github.com/users/cbargren/received_events","type":"User","site_admin":false},"created_at":"2017-07-17T21:14:00Z","updated_at":"2017-07-17T21:14:00Z","body":"I'd like to take a stab at implementing this!\r\n\r\nI tend to agree with @Moeriki's point about missing out on some important cases with @mysticatea's suggestion, but it would be nice to be able to specify the behavior of overrides in any case. I'd suggest combining the two proposals to some extent into something like this:\r\n```javascript\r\n\"curly\": [2, {\r\n  \"type\": \"multi\",\r\n  \"overrides\": {\r\n    \"type\": \"all\",\r\n    \"keywords\": [\"if\", \"else\"],\r\n    \"except\": [\"return\", \"continue\", \"break\"]\r\n  }\r\n}],\r\n```\r\n\r\n```javascript\r\nfunction foo() {\r\n  // We don't need curlies here because `while` is not an overridden keyword\r\n  while (a < 5) a++;\r\n\r\n  // We need it here because `if` is overridden and not excepted\r\n  if (a === 5) {\r\n    a++;\r\n  }\r\n  // We don't need it here because `else` is overridden, but `return` is excepted\r\n  else return true;\r\n}\r\n```\r\n\r\nOne thing to note is that I can't really think of a time when you'd want to have an exception in place for `return`s, but not `continue`s, etc. With that in mind, it might make sense to simplify that setting into just a boolean property that applies to all three control keywords (something like `exceptControlKeywords`, maybe?). If anyone has a counterexample on that, I'd be happy to backpedal on that suggestion, though.\r\n\r\nLet me know if anyone can think of any edge cases I'd be missing with this implementation. Otherwise, I'll probably get started on this tonight or tomorrow."}}
{"actor":{"display_login":"cbargren"}}