-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #148 Add cop for Entity new #161
Conversation
I'm guessing that it's trying to match on Your matcher looks close though. (Have you found the
One thing I wonder, is if the underscore in your matcher means it expects at least one param? Btw, a matcher is capable of capturing part of the node, so that you should be able to capture the class name and then reuse that in the error message eventually. |
Yea, you might want to replace And worth to add tests for both with and without arguments passed to |
a1cf10a
to
2f5b055
Compare
Got it to work know and added a bunch of more classes to check for |
config/default.yml
Outdated
@@ -209,6 +209,11 @@ SketchupRequirements/GlobalVariables: | |||
Reference: https://github.com/SketchUp/rubocop-sketchup/tree/main/manual/cops_requirements.md#globalvariables | |||
Enabled: true | |||
|
|||
SketchupRequirements/InitEntity: | |||
Description: Do not init SketchUp Entity objects with `new`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expand init
to initialize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be regenerated? bundle exec rake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still this init
usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed the one in the description
ea02ef6
to
d0c02e4
Compare
Ready for re-review! |
(send | ||
(const | ||
(const nil? :Sketchup) | ||
{:Face :Group :Edge :ConmponentInsstance :Image} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConmponentInsstance
=> ComponentInstance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to call a method from a matcher. Syntax uses something like #methodname
I think. But we could use that to make the node matcher look up a complete list of Sketchup::Entity
derived classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a method and also listed a whole bunch of more classes while at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. You're quickly ramping up the complexity. 👍
Spotted a couple of spelling mistakes. And got a suggestion on how we can cover all the entities instead of just a subset.
# them. | ||
class InitialiseEntity < SketchUp::Cop | ||
|
||
ENTITY_CLASSES = %i[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Known direct subclasses:
AttributeDictionaries, AttributeDictionary, Axes, Behavior, Curve, DefinitionList, Drawingelement, EdgeUse, Layer, LayerFolder, Layers, LineStyle, LineStyles, Loop, Material, Materials, Page, Pages, RenderingOptions, ShadowInfo, Style, Styles, Texture, Vertex
And then you have the subclasses of Drawinglement
:
ComponentDefinition, ComponentInstance, ConstructionLine, ConstructionPoint, Dimension, Edge, Face, Group, Image, SectionPlane, Text
|
||
subject(:cop) { described_class.new } | ||
|
||
entity_classes = %i[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just refer to the ENTITY_CLASSES
constant in the cop here, reuse that.
|
||
require 'spec_helper' | ||
|
||
describe RuboCop::Cop::SketchupRequirements::InitialiseEntity do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I messed up last round of comments, the correct spelling in Ruby is initialize
. (I don't know why I thought otherwise before.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are too British! :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (small nit: still using "init" in default.yml
)
04ea30a
to
bf3ba06
Compare
Work in progress.
My node matcher (
(send (const (const nil? :Sketchup) :Face) :new _)
) doesn't seem to catch anything.For now it should catch
Sketchup::Face.new
and skipEdge
andGroup
, but all 3 tests give identical results.I'm suspecting a syntax issue, but I'm not sure. @thomthom, can you have a look?