Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Remove unused variables (advanced) #12189

Closed
wants to merge 1 commit into from
Closed

Conversation

Ingramz
Copy link
Contributor

@Ingramz Ingramz commented Jul 18, 2016

Let's see how well this goes. 🙏

I was reading some text-editor related code and was mildly frustrated to find some unused variables. I added coffeescope for coffeelint and started manually excluding global classes and variables until it found the following unused variables/undefined references.

There are still unused variables in try ... catch unusedVariable statements, but these cannot be cleaned up as it requires a more up to date version of coffeescript dependency in grunt or the code won't transpile. Updated coffeescript.

If we do have a more recent version of coffeescript, grunt and a false positive regarding for x,y of z in coffeescope#7 has been fixed (which in programming speak is never), it might be worthwhile adding coffeescope permanently to find code like this.

Update 30.08.2016: There is still some configuration overhead with the coffeescope, as there are certain things that are defined in helpers and elsewhere, which would have to be whitelisted manually.

@winstliu
Copy link
Contributor

Might want to check out those failures in PaneContainerElement.

@za-creature
Copy link

coffeescope2 maintainer here.

If you think za-creature/coffeescope#7 is a blocker, I will escalate the crap out of it (can't promise a due date, but I can put in some time over the weekend)

@Ingramz
Copy link
Contributor Author

Ingramz commented Jul 18, 2016

@za-creature not necessarily, the larger blockers are "outdated" grunt (+ plugins) and coffee-script at the moment.

Also I am not sure how is one supposed to deal with Chromium/DOM and Node.js globals in this case so that it would be possible to distinguish them from undefined references (adding them manually seemed tedious and inefficient), but that becomes more of an issue when one would go about using it. RTFM

Thank you for the tool though, it's a shame that it isn't part of coffeelint out of the box.

@za-creature
Copy link

it's a shame that it isn't part of coffeelint out of the box.

I'm open to that, it's just that coffeelint has seen better days. I really wish the coffeescript organization would happen as coffeelint would have a lot to gain by being moved there.

@Ingramz
Copy link
Contributor Author

Ingramz commented Aug 16, 2016

@za-creature it looks like soon Grunt is being removed from the build process, which means that if we really wanted, we could propose adding coffeescope to the build workflow. How is it going with the issue number 7?

@za-creature
Copy link

I'm actually prepping a 1.0 release because I want to completely rework the configuration file. I'll be travelling abroad for the next two weeks, so I can't really promise a release date, but seeing as atom is probably the largest coffeescript codebase in existence, I'd definitely like to see this go through.

When's your ETA for Grunt removal? I'll try to squeeze a RC until then

@Ingramz
Copy link
Contributor Author

Ingramz commented Aug 18, 2016

I'm not affiliated with GH, it is just a small observation based on a pull request. By the looks of it there's still a week's worth of work left. There's really no hurry, feel free to take your time.

As far as this PR is concerned, I'll re-do the commits eventually.

@thomasjo
Copy link
Contributor

The commit history here needs some cleanup; as it stands it looks like you've got a duplicate of the "Remove unused variables" commit (e3b04b5 and d47209d). Probably the result of a merge gone wrong.

My recommendation would be to rebase on top of master and removing the duplicate commit, resulting in the branch only having a single commit. The alternative is to create a new branch/PR and cherry-pick d47209d into that branch. Let me know if you need any assistance with this, and I'll happily help you out 🙇

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 10, 2016

Yep, just a bad merge. Currently I am trying to figure out what's causing errors on Windows though. Something related to recent commits from past week.

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 11, 2016

@thomasjo I rebased the commit.

The changes from past week (or some caches have cleared) in combination with coffeescript version bump in this commit caused now-invalid references to fields in tabs and autocomplete-plus, which were easy to fix.

atom/tabs#374
atom/autocomplete-plus#768

There could be other ones in packages, which can be easily checked using coffeescope if coffeelint has been configured already. However, I am having trouble building Atom with packages from a different source (eg referencing a Github repo+branch or archive url in package.json like it's possible with npm), so I'm leaving this as it is until a "clean" build can be produced.

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 15, 2016

It looks like I might need to check all packages before this can be merged.

  • atom-dark-syntax
  • atom-dark-ui
  • atom-light-syntax
  • atom-light-ui
  • base16-tomorrow-dark-theme
  • base16-tomorrow-light-theme
  • one-dark-ui
  • one-light-ui
  • one-dark-syntax
  • one-light-syntax
  • solarized-dark-syntax
  • solarized-light-syntax
  • about
  • archive-view
  • autocomplete-atom-api
  • autocomplete-css
  • autocomplete-html
  • autocomplete-plus
  • autocomplete-snippets
  • autoflow
  • autosave
  • background-tips
  • bookmarks
  • bracket-matcher
  • command-palette
  • deprecation-cop
  • dev-live-reload
  • encoding-selector
  • exception-reporting
  • find-and-replace
  • fuzzy-finder
  • git-diff
  • go-to-line
  • grammar-selector
  • image-view
  • incompatible-packages
  • keybinding-resolver
  • line-ending-selector
  • link
  • markdown-preview
  • metrics
  • notifications
  • open-on-github
  • package-generator
  • settings-view
  • snippets
  • spell-check
  • status-bar
  • styleguide
  • symbols-view
  • tabs
  • timecop
  • tree-view
  • update-package-dependencies
  • welcome
  • whitespace
  • wrap-guide
  • language-c
  • language-clojure
  • language-coffee-script
  • language-csharp
  • language-css
  • language-gfm
  • language-git
  • language-go
  • language-html
  • language-hyperlink
  • language-java
  • language-javascript
  • language-json
  • language-less
  • language-make
  • language-mustache
  • language-objective-c
  • language-perl
  • language-php
  • language-property-list
  • language-python
  • language-ruby
  • language-ruby-on-rails
  • language-sass
  • language-shellscript
  • language-source
  • language-sql
  • language-text
  • language-todo
  • language-toml
  • language-xml
  • language-yaml

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 17, 2016

I completed checking the packages above and tried to do as many pull requests I could at a reasonable pace, but there's still at least quarter of the packages where there's still room for improvement regarding eliminating unused variables. I was mainly concerned of coffeescript >=1.9.0 compatibility for which I did appropriate pull requests.

Once updated versions of these make it to master, migration to newer coffeescript should be safe and this PR can potentially be merged.

@winstliu
Copy link
Contributor

Once updated versions of these make it to master

I haven't been bumping any of those packages unless you fixed variable referencing...do you want me to bump all of them, even if they just removed some unused variables?

@@ -1,4 +1,5 @@
{ipcRenderer} = require 'electron'
Grim = require 'grim'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 17, 2016

Only the ones where I have fixed variable referencing are required.

@winstliu
Copy link
Contributor

@Ingramz Can you remind me which ones those were again?

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 17, 2016

@winstliu
Copy link
Contributor

Done.

@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 26, 2016

I'm going to split this pull request into two, one that bumps the coffeescript version and only incorporates changes that are required for new coffeescript to function properly and one that only deals with removing unused variables. Should reduce the burden that comes with reviewing.

@Ingramz Ingramz changed the title Remove unused variables Remove unused variables (advanced) Sep 26, 2016
@Ingramz
Copy link
Contributor Author

Ingramz commented Sep 26, 2016

I rebased this pull request and left in only the less trivial changes, requires #12780 before this can be merged due to removed unused variable names in catch clauses.

@@ -120,27 +120,6 @@ warnIfLeakingPathSubscriptions = ->
console.error("WARNING: Leaking subscriptions for paths: " + watchedPaths.join(", "))
pathwatcher.closeAllWatchers()

ensureNoDeprecatedFunctionsCalled = ->
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be nice to keep around for when Atom 2.0 approaches and we start deprecating stuff again.

@Ingramz Ingramz closed this Nov 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants