-
Notifications
You must be signed in to change notification settings - Fork 4
lint: collect unused files #22
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
base: master
Are you sure you want to change the base?
Conversation
tyanas
left a comment
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.
some tests would be great!
lib/lint/reporter/process-warns.js
Outdated
| var isChildProcess = typeof process.send == 'function'; // child process has send method | ||
| var collectFiles = require('./collectFiles'); | ||
|
|
||
| module.exports = function(flow, options){ |
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.
The interface was changed.
Have you considered adding [js]docs? Like what kind of objects should be flow and options now.
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.
This module should be untouched (see below).
lib/lint/index.js
Outdated
| } | ||
|
|
||
| cursor.linkTo.forEach(function(link){ | ||
| // prevent to handling files that already handled |
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.
prevent to handling files that are already handled
291afb4 to
b241c96
Compare
e902dad to
f1528ff
Compare
|
Now we supports: And <b:define name="someState" type="enum" values="prop1 prop2"/>
<div>
{l10n:enum.{someState}}
</div>
|
a8e1778 to
8460b42
Compare
lib/lint/command.js
Outdated
| .option('--no-color', 'Suppress color output') | ||
| .option('--silent', 'No any output') | ||
|
|
||
| .option('--warn-unused-files <base>', 'Warn about unused files in specified path. Do not use with --js-cut-dev. It might cause incorrect result') |
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.
.option('--warn-unused-files <dir>', 'Warn about unused files for specified path. Avoid using with --js-cut-dev since it might cause to incorrect results')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.
ok
lib/common/files.js
Outdated
| */ | ||
|
|
||
| function File(manager, cfg){ | ||
| this.uniqueId = lastFileId++; |
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.
Not needed, see below
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.
ok
lib/common/files.js
Outdated
| this.readInfo = []; | ||
|
|
||
| // helpers | ||
| this.unixpath = unixpath; |
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.
Redundant, should be removed
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.
ok
| while (cursor = stack.pop()) | ||
| { | ||
| // mark file as handled | ||
| handled[cursor.uniqueId] = true; |
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.
Use [Weak]Map, Luke!
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 thought about Map, but it seems slow
But ok, I'll use it
lib/lint/index.js
Outdated
| function(flow){ | ||
| flow.result = require('./reporter/process-warns')(flow.warns, options.filter); | ||
| if (options.warnUnusedFiles) | ||
| collectUsed.files(flow); |
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.
Bad pattern: function has a hidden side effect. As I realised it adds usedFiles to flow – it's confusing and should be explicit.
lib/lint/reporter/process-warns.js
Outdated
| var isChildProcess = typeof process.send == 'function'; // child process has send method | ||
| var collectFiles = require('./collectFiles'); | ||
|
|
||
| module.exports = function(flow, options){ |
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.
This module should be untouched (see below).
lib/lint/collectUsed/files.js
Outdated
| } | ||
| }); | ||
|
|
||
| flow.usedFiles = { |
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.
Should returns something rather than assign to flow.
lib/lint/collectUsed/files.js
Outdated
| return file.filename && (basePath + file.filename).indexOf(collectPath + '/') === 0; | ||
| } | ||
|
|
||
| module.exports = function collectUsedFiles(flow){ |
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 is much simplier way to find used files for some path:
var usedFiles = flow.files.queue
.filter(function(file) {
return file.fsFilename.indexOf(flow.options.warnUnusedFiles + '/') === 0;
})
.map(...);
lib/lint/index.js
Outdated
| if (options.warnUnusedFiles) | ||
| collectUsed.files(flow); | ||
| }, | ||
| function(flow){ |
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.
No need for two functions here.
lib/lint/index.js
Outdated
| var command = require('./command'); | ||
| var chalk = require('chalk'); | ||
| var isChildProcess = typeof process.send == 'function'; // child process has send method | ||
| var collectUsed = { |
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.
No win to use an object here
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.
l10n will be here soon :)
- decoupled flow and collectors - clear reporters
| } | ||
|
|
||
| // warn about unused files | ||
| for (var unusedFile in unusedFiles) |
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 believe this loop doesn't needed and unusedFiles map is redundant
| var collectedFiles = collectFiles(basePath); | ||
|
|
||
| usedFilesInfo.items.forEach(function(filename){ | ||
| usedFiles[usedFilesInfo.basePath + filename] = true; |
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.
Why not delete collectedFiles[usedFile] here? usedFiles is redundant
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.
cause it will affect flow.usedFiles
seems like it's not good
| delete collectedFiles[usedFile]; | ||
|
|
||
| for (var unusedName in collectedFiles) { | ||
| unusedName = unusedName.slice(process.cwd().length); |
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.
require('path').relative(...) ?
Merge after basisjs/basisjs#163 otherwise the linter will show the wrong result for
<b:style src="./some.css"/>