msiebuhr / slint

Lint-tool for web projects
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

Lint contents of git repo #19

Closed papandreou closed 11 years ago

papandreou commented 11 years ago

I finally assembled the tech to accomplish this:

https://github.com/papandreou/node-cachedfs https://github.com/papandreou/node-fsplusgit https://github.com/papandreou/node-gitfakefs

What's still missing is finding a good way to expose it. As a starting point, I wired things up and added a --git switch that figures out where the .git folder for your project is, then resolves your paths relative to the virtual directory that exposes the contents of the index. I put it on the fsPlusGit branch: https://github.com/msiebuhr/slint/commit/03e9e3052803ed36b2c25d7faab963c06db266b2

It seems to work:

andreas@andreas-ThinkPad-T500:~/work/slint$ git status
# On branch fsPlusGit
nothing to commit (working directory clean)
andreas@andreas-ThinkPad-T500:~/work/slint$ slint --git slint.json 
andreas@andreas-ThinkPad-T500:~/work/slint$ echo qivweivqe > foo.js
andreas@andreas-ThinkPad-T500:~/work/slint$ slint --git slint.json 
andreas@andreas-ThinkPad-T500:~/work/slint$ git add foo.js
andreas@andreas-ThinkPad-T500:~/work/slint$ slint --git slint.json 
foo.js: line 1, col 1, Expected an assignment or function call and instead saw an expression.
foo.js: line 1, col 10, Missing semicolon.
andreas@andreas-ThinkPad-T500:~/work/slint$ 

As for the mode that only lints the actually changed files, that is supported by those helper modules I built (/path/to/repo.git/gitFakeFs/changesInIndex/...). We need to think a bit about how to use that, though, as you usually won't have changed your slint.json file, which will make it absent. Also, the less linter will have trouble resolving @imports pointing at files that haven't changed. Clearly some things still need to be fetched from /path/to/repo.git/gitFakeFs/index/....

papandreou commented 11 years ago

Ok, I think I figured out how this should work and implemented the following on the fsPlusGit branch:

1) When determining the set of files to lint, look for files that have staged changes. Ignore files not under version control and files that are identical to the version in HEAD. 2) When reading files and reporting file names to linters, use what's staged in the index, but fall back to what's in the working copy. This ensures that auto-generated files are present in case eg. the less linter needs to @import them. It uses the virtual .git/gitFakeFs/indexOrWorkingCopy dir in fsPlusGit to support this feature.

Let me know if you think this is in a state to land on master.

There's a minor thing missing, but I don't think it should be a blocker: https://github.com/papandreou/node-gitfakefs/issues/1

papandreou commented 11 years ago

Landed on master.