Skip to content

Commit

Permalink
feat: bump node version; npm audit fix; npm run lint -- --fix (#41)
Browse files Browse the repository at this point in the history
* feat: removed the changed on package-lock

* feat: removed @zeit/ncc as it's not maintained and changed it to @vercel/ncc
  • Loading branch information
neo-antonio-canabrava authored Jul 5, 2024
1 parent baa4aa6 commit d695c34
Show file tree
Hide file tree
Showing 13 changed files with 3,706 additions and 3,590 deletions.
10 changes: 8 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"extends": "eslint-config-neo/config-backend",
"rules": {
"no-console": "off",
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }]
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"autofix/no-unused-vars": "off"
}
}
}
46 changes: 23 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Cache node modules
uses: actions/cache@preview
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install
run: yarn --frozen-lockfile --prefer-offline --non-interactive
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Test
run: yarn test -- --coverage
- name: Codecov
uses: codecov/codecov-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '20'
- name: Cache node modules
uses: actions/cache@preview
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install
run: yarn --frozen-lockfile --prefer-offline --non-interactive
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Test
run: yarn test -- --coverage
- name: Codecov
uses: codecov/codecov-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.2.0 (July 5, 2024)

- npm audit fix
- bumped node version required to 20
- bumped manually other libraries

## 1.1.2 (October 17, 2020)

- Changed `node_modules` glob pattern to also exclude nested node_modules
Expand All @@ -11,7 +17,7 @@

## 1.1.0 (March 9, 2020)

- Add `ignore-numbers` argument which takes an array of numbers you want to ignore
- Add `ignore-numbers` argument which takes an array of numbers you want to ignore

## 1.0.4 (December 10, 2019)

Expand Down
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module.exports = {
'!<rootDir>/node_modules/',
'!<rootDir>/build/',
'!<rootDir>/dist/',
'!<rootDir>/*.js'
'!<rootDir>/*.js',
],
globals: {
'ts-jest': {
tsConfig: '<rootDir>/test/tsconfig.json'
}
tsConfig: '<rootDir>/test/tsconfig.json',
},
},
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/dist/', '<rootDir>/config.*.js']
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/dist/', '<rootDir>/config.*.js'],
};
20 changes: 10 additions & 10 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.1.2",
"version": "1.2.0",
"author": "Neo Financial Engineering <engineering@neofinancial.com>",
"license": "MIT",
"main": "build/index.js",
Expand All @@ -13,7 +13,7 @@
"url": "https://github.com/neofinancial/ccscan"
},
"engines": {
"node": ">=8.3.0"
"node": ">=20.0.0"
},
"scripts": {
"start": "./bin/ccscan.js",
Expand Down Expand Up @@ -45,22 +45,22 @@
"@types/line-reader": "^0.0.28",
"@types/node": "^12.11.7",
"@types/yargs": "^13.0.3",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"chalk": "^2.4.2",
"eslint": "^6.0.0",
"eslint-config-neo": "~0.5.1",
"eslint": "^8.34.0",
"eslint-config-neo": "^0.11.1",
"fast-luhn": "^1.0.4",
"globby": "^10.0.1",
"husky": "^3.0.8",
"jest": "^24.9.0",
"jest": "^29.7.0",
"line-reader": "^0.4.0",
"lint-staged": "^9.4.2",
"prettier": "^1.19.0",
"prettier": "^3.3.2",
"rimraf": "^3.0.0",
"strip-ansi": "^5.2.0",
"ts-jest": "^24.1.0",
"ts-jest": "^29.1.5",
"ts-node": "^8.4.1",
"typescript": "3.7.3",
"typescript": "5.5.3",
"yargs": "^14.2.0"
}
}
}
47 changes: 25 additions & 22 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ const defaultArgs = {
ignoreNumbers: [],
luhnCheck: true,
silent: false,
verbose: false
verbose: false,
};

const isCardNumber = (suspect: string, ignoreNumbers?: string[]): boolean => {
const trimmedSuspect = suspect.replace(/[\s-]+/g, '');
const trimmedSuspect = suspect.replaceAll(/[\s-]+/g, '');

return !ignoreNumbers?.includes(trimmedSuspect) && luhn(trimmedSuspect);
}
};

const showMatches = async (
fileName: string,
matches: RegExpMatchArray,
args: Args
args: Args,
): Promise<void> => {
return new Promise((resolve): void => {
const filePath = path.isAbsolute(fileName) ? fileName : path.join(process.cwd(), fileName);
Expand All @@ -46,30 +46,30 @@ const showMatches = async (
lineNumber++;

for (const match of matches) {
if (line.match(new RegExp(`.*${match}.*`))) {
if (new RegExp(`.*${match}.*`).test(line)) {
const columnNumber = line.search(match) + 1;

if (args.luhnCheck && isCardNumber(match, args.ignoreNumbers)) {
error = true;
outputLines.push(
`${chalk.gray(`${lineNumber}:${columnNumber}`.padEnd(8))} ${chalk.red(
'error'.padEnd(6)
)} ${line.replace(match, chalk.red(match))}`
'error'.padEnd(6),
)} ${line.replace(match, chalk.red(match))}`,
);
} else if (!args.luhnCheck) {
if (isCardNumber(match, args.ignoreNumbers)) {
error = true;
outputLines.push(
`${chalk.gray(`${lineNumber}:${columnNumber}`.padEnd(8))} ${chalk.red(
'error'.padEnd(6)
)} ${line.replace(match, chalk.red(match))}`
'error'.padEnd(6),
)} ${line.replace(match, chalk.red(match))}`,
);
} else {
warning = true;
outputLines.push(
`${chalk.gray(`${lineNumber}:${columnNumber}`.padEnd(8))} ${chalk.yellow(
'warn'.padEnd(6)
)} ${line.replace(match, chalk.yellow(match))}`
'warn'.padEnd(6),
)} ${line.replace(match, chalk.yellow(match))}`,
);
}
}
Expand All @@ -95,15 +95,18 @@ const showMatches = async (
};

const scanFile = async (fileName: string, args: Args): Promise<boolean> => {
const contents = fs.readFileSync(fileName, 'utf-8');
const contents = fs.readFileSync(fileName, 'utf8');
const matches = args.luhnCheck
? contents.match(/\b[2-6]{1}\d{3}[\s-]*\d{4}[\s-]*\d{4}[\s-]*\d{4}[\s-]*\b/gm)
: contents.match(/\b[1-9]{1}\d{3}[\s-]*\d{4}[\s-]*\d{4}[\s-]*\d{4}[\s-]*\b/gm);
? contents.match(/\b[2-6]\d{3}(?:[\s-]*\d{4}){3}[\s-]*\b/gm)
: contents.match(/\b[1-9]\d{3}(?:[\s-]*\d{4}){3}[\s-]*\b/gm);

if (matches && matches.length > 0) {
!args.silent && (await showMatches(fileName, matches, args));

if (!args.luhnCheck || matches.filter(match => isCardNumber(match, args.ignoreNumbers)).length > 0) {
if (
!args.luhnCheck ||
matches.some((match) => isCardNumber(match, args.ignoreNumbers))
) {
return true;
}
}
Expand Down Expand Up @@ -154,38 +157,38 @@ const run = async (): Promise<void> => {
yargs.positional('files', {
default: '**/*.{ts,js}',
describe: 'Files to scan',
type: 'string'
type: 'string',
}),
handler: async (args: Args): Promise<void> => {
if ((await scanFiles(args)).length > 0) {
process.exit(1);
}
}
},
})
.demandCommand(1)
.option('exclude', {
default: [],
describe: 'exclude pattern',
type: 'array'
type: 'array',
})
.option('ignore-numbers', {
default: [],
describe: 'ignore these numbers',
type: 'array',
string: true
string: true,
})
.option('luhn-check', {
default: true,
describe: 'check if suspected card number passes the luhn check',
type: 'boolean'
type: 'boolean',
})
.option('silent', {
describe: 'do not show any output',
type: 'boolean'
type: 'boolean',
})
.option('verbose', {
describe: 'show all scanned files',
type: 'boolean'
type: 'boolean',
})
.conflicts('silent', 'verbose')
.help().argv;
Expand Down
16 changes: 8 additions & 8 deletions test/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JavaScript card numbers are detected 1`] = `
Array [
[
"test/fixtures/javascript/bad.js",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand All @@ -19,7 +19,7 @@ Array [
`;

exports[`JavaScript card numbers are detected in verbose mode 1`] = `
Array [
[
"test/fixtures/javascript/bad.js",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand All @@ -39,7 +39,7 @@ Array [
`;

exports[`JavaScript card-like numbers are detected when luhn check is disabled 1`] = `
Array [
[
"test/fixtures/javascript/bad.js",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand Down Expand Up @@ -69,7 +69,7 @@ Array [
`;

exports[`JavaScript files with both ignored and non-ignored card numbers are included 1`] = `
Array [
[
"test/fixtures/javascript/bad.js",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand All @@ -86,7 +86,7 @@ Array [
`;

exports[`TypeScript card numbers are detected 1`] = `
Array [
[
"test/fixtures/typescript/bad.ts",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand All @@ -104,7 +104,7 @@ Array [
`;

exports[`TypeScript card numbers are detected in verbose mode 1`] = `
Array [
[
"test/fixtures/typescript/bad.ts",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand All @@ -124,7 +124,7 @@ Array [
`;

exports[`TypeScript card-like numbers are detected when luhn check is disabled 1`] = `
Array [
[
"test/fixtures/typescript/bad.ts",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand Down Expand Up @@ -154,7 +154,7 @@ Array [
`;

exports[`TypeScript files with both ignored and non-ignored card numbers are included 1`] = `
Array [
[
"test/fixtures/typescript/bad.ts",
undefined,
" 3:29 error // card number in a comment 5555554240233167",
Expand Down
Loading

0 comments on commit d695c34

Please sign in to comment.