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

Ability to ignore files #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";
var program = require("commander");
var similar = require("./similar");
var ignore = require("ignore");
var fs_collector = require("./cli/file_collector");
var pkg = require("./../package.json");
var compare = function (targets, opts) {
var files = fs_collector.files(targets);
var nocolors = !!opts.disablecolors;
fs_collector.print(files, nocolors);
var _a = similar.compare(files, opts), js = _a.js, ts = _a.ts;
var filter = ignore();
var filtered_files = filter.add(opts.ignore).filter(files);
fs_collector.print(filtered_files, nocolors);
var _a = similar.compare(filtered_files, opts), js = _a.js, ts = _a.ts;
similar.print(js, nocolors);
similar.print(ts, nocolors);
};
Expand All @@ -24,6 +27,8 @@ var configure = function () {
("[default=" + similar.DEFAULT_NGRAM_LENGTH + ",2,3...]"))
.option("-d, --disablecolors", "Disable color output")
.option("--estype [value]", "Set the JavaScript parser source type [default=module,script]")
.option("-i, --ignore <glob>", "Set glob for files that will be ignored. WARNING: You should " +
"wrap glob in quote, otherwise you may get wrong result")
.action(compare);
program.on("--help", function () {
console.log(" Command specific help:");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"escodegen": "^1.8.1",
"esprima": "^4.0.0",
"estraverse": "^4.2.0",
"ignore": "^3.3.3",
"lodash": "^4.17.4",
"typescript": "^2.3.4",
"walk-sync": "^0.3.2"
Expand Down
14 changes: 12 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import program = require("commander")
import similar = require("./similar")
import ignore = require("ignore");
import fs_collector = require("./cli/file_collector")

const pkg = require("./../package.json")
Expand All @@ -10,10 +11,14 @@ const compare = (
) => {
const files = fs_collector.files(targets)
const nocolors : boolean = !!opts.disablecolors
const filter = ignore();
// we need to cast result of ignore.filter to any
// because of typings of ignore package
const filtered_files = filter.add(opts.ignore).filter(files) as any;

fs_collector.print(files, nocolors)
fs_collector.print(filtered_files, nocolors)

const { js, ts } = similar.compare(files, opts)
const { js, ts } = similar.compare(filtered_files, opts)

similar.print(js, nocolors)
similar.print(ts, nocolors)
Expand All @@ -40,6 +45,11 @@ const configure = () => {
.option(
"--estype [value]",
"Set the JavaScript parser source type [default=module,script]")
.option(
"-i, --ignore <glob>",
"Set glob for files that will be ignored. WARNING: You should " +
"wrap glob in quote, otherwise you may get wrong result"
)
.action(compare)

program.on("--help", () => {
Expand Down
137 changes: 137 additions & 0 deletions test/fixtures/cli_output/test.igore.ts.color.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
found: test/fixtures/system/test-es.js
found: test/fixtures/system/test.copy.js
found: test/fixtures/system/test.js

76% match

in: test/fixtures/system/test-es.js

 9: function diag(x, y) {
10: return sqrt(square(x) + square(y));
11: }

13: function dude(x, y) {
14: return sqrt(square(x ^ 2) + square(y));
15: }

83% match

in: test/fixtures/system/test.js

63: function (a, b) {
64: const dx = a.x - b.x;
65: const dy = a.y - b.y;
66: return Math.sqrt(dx * dx + dy * dy);
67: }

70: function (an, ab) {
71: const dx = an.x - ab.x;
72: const dy = an.y - ab.y;
73: return Math.sqrt(dx * dx + dy * dy);
74: }

89% match

in: test/fixtures/system/test.js

27: class FooBazzzz {
28: constructor() {
29: }
30: static get area() {
31: console.log('a');
32: console.log('b');
33: console.log('c');
34: console.log('c');
35: console.log('c');
36: }
37: }

40: class FooBarrr {
41: constructor() {
42: }
43: static get area() {
44: console.log('a');
45: console.log('b');
46: console.log('c');
47: console.log('c');
48: console.log('c');
49: }
50: }

93% match

in: test/fixtures/system/test.copy.js

1: (a, b) => {
2: console.log();
3: if (!a) {
4: console.log(a);
5: }
6: }

in: test/fixtures/system/test.js

1: (a, b) => {
2: console.log(b);
3: if (a) {
4: console.log(a);
5: }
6: }

93% match

in: test/fixtures/system/test.js

1: (a, b) => {
2: console.log(b);
3: if (a) {
4: console.log(a);
5: }
6: }

 9: (a, b) => {
10: console.log();
11: if (!a) {
12: console.log(a);
13: }
14: }

100% match

in: test/fixtures/system/test.copy.js

1: (a, b) => {
2: console.log();
3: if (!a) {
4: console.log(a);
5: }
6: }

in: test/fixtures/system/test.js

 9: (a, b) => {
10: console.log();
11: if (!a) {
12: console.log(a);
13: }
14: }

100% match

in: test/fixtures/system/test.js

31: function () {
32: console.log('a');
33: console.log('b');
34: console.log('c');
35: console.log('c');
36: console.log('c');
37: }

44: function () {
45: console.log('a');
46: console.log('b');
47: console.log('c');
48: console.log('c');
49: console.log('c');
50: }
11 changes: 11 additions & 0 deletions test/spec/system.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ CLI_OUTPUT_TEST_JS_TS_DIR = path
.join FIXTURES, "cli_output", "test.dir.txt"
CLI_OUTPUT_TEST_JS_TS_DIR_COLOR = path
.join FIXTURES, "cli_output", "test.dir.color.txt"
CLI_OUTPUT_TEST_IGNORE_TS_COLOR = path
.join FIXTURES, "cli_output", "test.igore.ts.color.txt"

cli_output = (path) ->
if on_win
Expand Down Expand Up @@ -183,3 +185,12 @@ describe "system :: cli", ->
expect(error.code).to.eql 0
expect(stdout).to.eql(cli_output CLI_OUTPUT_TEST_JS_TS_DIR)
done()

it "can ignore ts files", (done) ->
cmd = "analyze -i *.ts #{SYSTEM}"

system.exec cmd,
(error, stdout, stderr) ->
expect(error.code).to.eql 0
expect(stdout).to.eql(cli_output CLI_OUTPUT_TEST_IGNORE_TS_COLOR)
done()