Skip to content
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: duplicate declarations by naming classes more thoroughly #52

Closed

Conversation

knownasilya
Copy link

@knownasilya knownasilya commented Jan 17, 2019

Resolves #51

This doesn't support MU, only mixed layouts.
Ran it against one app and it transformed 305 files with

node ~/ember-es6-class-codemod/bin/cli.js ember-object --decorators=true --quotes=single app/**/*.js

Copy link
Contributor

@ssutar ssutar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A minor comment about removing debugger

const dirWithoutFile = path.dirname(appFilePath);
// Only keep no more then the last two directories
// Ignore any that are plural of the superclass name
// debugger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@knownasilya
Copy link
Author

All set.

Copy link
Contributor

@ssutar ssutar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pzuraq Please review and merge! LGTM

@knownasilya
Copy link
Author

Ping @pzuraq

Copy link
Collaborator

@pzuraq pzuraq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for something along the lines of app/users/route.js? That will be a common case for pods. I'd also like to test the superclass functionality if that's possible, though I realize that may be trickier. Could require a unit test, and some way to mock the superclass data.

@@ -473,8 +474,44 @@ function getClassName(
type = ""
) {
const varDeclaration = getClosetVariableDeclaration(j, eoCallExpression);
const filePathSplit = filePath.startsWith("app/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to make this configurable, I know some folks put their pods in different directories

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the case for everyone, even if their pods are in a different directory. The cases this would need to change for is engines, dummy app, and MU.

const fileNameWithoutExt = path.basename(appFilePath, "js");
const superClassNameNotInPath =
superClassName &&
capitalizeFirstLetter(camelCase(fileNameWithoutExt)) !== superClassName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding here is that superClassName may not always be a base class like Route or Controller. It could be a different base route class defined within the app. Does this make sense still in that case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe a check if the base class is an Ember primitive?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to figure out what the super class is, and what the "kind" is (e.g. Route, Controller, Component, etc). This can be done during our analysis with Dyfactor pretty easily, we may just need to record both and pass them forward.

@knownasilya
Copy link
Author

@pzuraq regarding app/users/route.js, this test is basically that: https://github.com/scalvert/ember-es6-class-codemod/pull/52/files#diff-ee12effcab6c0b1e8d4aea25d6eac70e

@@ -0,0 +1 @@
export default class UsersDefaultImportExportInputRoute extends Route {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does test whether or not the folder and the file name will be prepended to the class, but I think we should explicitly test the case where the file name is the name of the class/type (e.g. route.js). This is definitely going to be the most common case with pods, and I'd like to make sure that it's under test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to setup that kind of test, seems output and input need to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pzuraq any thoughts on how we'd set this up?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this may need a fix upstream, I'll see what I can do

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just recording here real quick because I'm not sure when @rwjblue or I will have time do it, but we chatted and figured the best solution here would be to rename the input files so that they drop the .input part before running tests in codemod-cli

@pzuraq pzuraq mentioned this pull request Feb 12, 2019
@vlascik
Copy link

vlascik commented Apr 16, 2019

This PR works well on files in app/ , but doesn't work on files in addon/ folder.

In transforms/helpers/parse-helper.js -> getClassName(), filePathSplit should also count with the possibility of codemod being used inside an addon perhaps?

@knownasilya
Copy link
Author

@vlascik think you could take a stab at a PR that fixes it against this PR?

@pzuraq
Copy link
Collaborator

pzuraq commented Aug 16, 2019

Superceded by #177

@pzuraq pzuraq closed this Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate declarations
4 participants