Skip to content

Commit

Permalink
Luhn check behaviour + typescript upgrade (#3)
Browse files Browse the repository at this point in the history
* When luhn-check is enabled, scanFile will now run a luhn check before flagging a file. Previously the luhn check only affected console output logic.
* Upgrading to TypeScript 3.7.3

* Update CHANGELOG.md


Co-authored-by: Ian Sutherland <[email protected]>
  • Loading branch information
usernameseb and iansu committed Dec 10, 2019
1 parent 138c5a4 commit 7aba008
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 213 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.4 (December 10, 2019)

- When `luhn-check` is enabled, `scanFile` will now run a luhn check before flagging a file. Previously the luhn check only affected console output logic.
- Upgrade to TypeScript 3.7.3

## 1.0.3 (December 10, 2019)

- Changed `main` property in `package.json` to `build/index.js` to match the ncc build output.
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ccscan",
"description": "Scan files for credit card numbers",
"version": "1.0.3",
"version": "1.0.4",
"author": "Neo Financial Engineering <[email protected]>",
"license": "MIT",
"main": "build/index.js",
Expand Down Expand Up @@ -47,20 +47,20 @@
"@types/yargs": "^13.0.3",
"@zeit/ncc": "^0.20.5",
"chalk": "^2.4.2",
"eslint": "^5.16.0",
"eslint-config-neo": "~0.3.3",
"eslint": "^6.0.0",
"eslint-config-neo": "~0.5.1",
"fast-luhn": "^1.0.4",
"globby": "^10.0.1",
"husky": "^3.0.8",
"jest": "^24.9.0",
"line-reader": "^0.4.0",
"lint-staged": "^9.4.2",
"prettier": "^1.18.2",
"prettier": "^1.19.0",
"rimraf": "^3.0.0",
"strip-ansi": "^5.2.0",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"typescript": "~3.5.3",
"typescript": "3.7.3",
"yargs": "^14.2.0"
}
}
12 changes: 7 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ const scanFile = async (fileName: string, args: Args): Promise<boolean> => {
if (matches && matches.length > 0) {
!args.silent && (await showMatches(fileName, matches, args));

return true;
} else {
!args.silent && args.verbose && console.log(chalk.gray(fileName));

return false;
if (!args['luhn-check'] || matches.filter(luhn).length > 0) {
return true;
}
}

!args.silent && args.verbose && console.log(chalk.gray(fileName));

return false;
};

const scanFiles = async (args: Args): Promise<string[]> => {
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Array [
" 10:37 warn const cardNumberMultipleDashes = '1234--1234--1234--1234';",
" 11:54 warn const cardNumberInString = 'This is a card number: 1234123412341234';",
" 12:43 warn const cardNumberInStringNoSpaces = 'text1234123412341234text';",
" 13:33 warn const cardNumberWithThrees = '3333333333333333';",
undefined,
]
`;
Expand Down Expand Up @@ -124,6 +125,7 @@ Array [
" 10:37 warn const cardNumberMultipleDashes = '1234--1234--1234--1234';",
" 11:54 warn const cardNumberInString = 'This is a card number: 1234123412341234';",
" 12:43 warn const cardNumberInStringNoSpaces = 'text1234123412341234text';",
" 13:33 warn const cardNumberWithThrees = '3333333333333333';",
undefined,
]
`;
6 changes: 3 additions & 3 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const formatConsoleOutput = (consoleOutput: string[][]): string[] => {
};

beforeAll(() => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
});

afterAll(() => {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('TypeScript', () => {
expect(
await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}', 'luhn-check': false })
).toEqual(['test/fixtures/typescript/bad.ts', 'test/fixtures/typescript/questionable.ts']);
expect(consoleLogSpy).toHaveBeenCalledTimes(23);
expect(consoleLogSpy).toHaveBeenCalledTimes(24);
expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot();
});

Expand Down Expand Up @@ -96,7 +96,7 @@ describe('JavaScript', () => {
expect(
await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}', 'luhn-check': false })
).toEqual(['test/fixtures/javascript/bad.js', 'test/fixtures/javascript/questionable.js']);
expect(consoleLogSpy).toHaveBeenCalledTimes(23);
expect(consoleLogSpy).toHaveBeenCalledTimes(24);
expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot();
});

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/javascript/bad.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */

// card number in a comment 5555554240233167
// two card numbers in a comment 5555554240233167 1234123412341234
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/javascript/good.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */

// not a card number in a comment 12555555424023316712334

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/javascript/questionable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */

// card number in a comment 1234123412341234

Expand All @@ -10,6 +10,7 @@ const doSomething = () => {
const cardNumberMultipleDashes = '1234--1234--1234--1234';
const cardNumberInString = 'This is a card number: 1234123412341234';
const cardNumberInStringNoSpaces = 'text1234123412341234text';
const cardNumberWithThrees = '3333333333333333';
};

module.exports = doSomething;
1 change: 1 addition & 0 deletions test/fixtures/typescript/questionable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const doSomething = () => {
const cardNumberMultipleDashes = '1234--1234--1234--1234';
const cardNumberInString = 'This is a card number: 1234123412341234';
const cardNumberInStringNoSpaces = 'text1234123412341234text';
const cardNumberWithThrees = '3333333333333333';
};

export default doSomething;
Loading

0 comments on commit 7aba008

Please sign in to comment.