Skip to content

Commit 22f67cf

Browse files
dafyddcrosbyfacebook-github-bot
authored andcommitted
open-source PythonCaps
Summary: This Cop is simple and has good pedagogical value, so I'd like to use it in external talks as well. Differential Revision: D70659250 fbshipit-source-id: 1b885f8b30e11ff97528a109567d5447c4bca50d
1 parent c3c981d commit 22f67cf

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

cookstyle/PythonCaps.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2025-present, Meta Platforms, Inc. and affiliates
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
module RuboCop::Cop::Chef::Meta
17+
class PythonCaps < Base
18+
extend AutoCorrector
19+
MSG = fb_msg('It looks like you are using Python syntax in Ruby, ' +
20+
'change to true or false')
21+
22+
# Check if True or False are included
23+
def_node_matcher :casgn_caps_true_false?, <<-PATTERN
24+
(casgn nil? {:False :True} _?)
25+
PATTERN
26+
27+
def_node_matcher :const_caps_true_false?, <<-PATTERN
28+
(const nil? {:False :True} _?)
29+
PATTERN
30+
31+
def on_casgn(node)
32+
expression = casgn_caps_true_false?(node)
33+
return unless expression
34+
add_offense(node, :severity => :warning)
35+
end
36+
37+
def on_const(node)
38+
expression = const_caps_true_false?(node)
39+
return unless expression
40+
add_offense(node,
41+
:severity => :warning) do |corrector|
42+
corrector.replace(node, node.short_name.to_s.downcase)
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)