Skip to content

Commit 71928ae

Browse files
authored
refactor: port is-ignored ts (#675)
* chore: add ts and jest config * chore: add ts related deps * refactor: port is-ignored to ts * style: apply prettier rules
1 parent 2bde134 commit 71928ae

12 files changed

+284
-233
lines changed

@commitlint/is-ignored/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./lib";

@commitlint/is-ignored/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports = require('./lib').default;
2+
module.exports.default = module.exports;

@commitlint/is-ignored/jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node'
4+
};

@commitlint/is-ignored/package.json

+11-31
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,16 @@
22
"name": "@commitlint/is-ignored",
33
"version": "8.0.0",
44
"description": "Lint your commit messages",
5-
"main": "lib/index.js",
65
"files": [
76
"lib/"
87
],
98
"scripts": {
10-
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
9+
"build": "tsc",
1110
"deps": "dep-check",
1211
"pkg": "pkg-check",
13-
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
14-
"test": "ava -c 4 --verbose",
15-
"watch": "babel src --out-dir lib --watch --source-maps"
16-
},
17-
"ava": {
18-
"files": [
19-
"src/**/*.test.js",
20-
"!lib/**/*"
21-
],
22-
"source": [
23-
"src/**/*.js",
24-
"!lib/**/*"
25-
],
26-
"babel": "inherit",
27-
"require": [
28-
"babel-register"
29-
]
30-
},
31-
"babel": {
32-
"presets": [
33-
"babel-preset-commitlint"
34-
]
12+
"start": "concurrently \"jest --watchAll\" \"tsc -w\"",
13+
"test": "jest",
14+
"watch": "tsc -w"
3515
},
3616
"engines": {
3717
"node": ">=4"
@@ -56,17 +36,17 @@
5636
},
5737
"license": "MIT",
5838
"devDependencies": {
59-
"@commitlint/parse": "^8.0.0",
39+
"@commitlint/parse": "8.0.0",
6040
"@commitlint/test": "8.0.0",
61-
"@commitlint/utils": "^8.0.0",
62-
"ava": "0.22.0",
63-
"babel-cli": "6.26.0",
64-
"babel-preset-commitlint": "^8.0.0",
65-
"babel-register": "6.26.0",
41+
"@commitlint/utils": "8.0.0",
42+
"@types/jest": "^24.0.13",
6643
"concurrently": "3.5.1",
67-
"cross-env": "5.1.1"
44+
"jest": "^24.8.0",
45+
"ts-jest": "^24.0.2",
46+
"typescript": "^3.5.1"
6847
},
6948
"dependencies": {
49+
"@types/semver": "^6.0.0",
7050
"semver": "6.1.1"
7151
}
7252
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import semver from 'semver';
2+
3+
export type Matcher = (commit: string) => boolean;
4+
5+
const isSemver = (c: string): boolean => {
6+
const firstLine = c.split('\n').shift();
7+
8+
if (typeof firstLine !== 'string') {
9+
return false;
10+
}
11+
12+
const stripped = firstLine.replace(/^chore(\([^)]+\))?:/, '').trim();
13+
return semver.valid(stripped) !== null;
14+
};
15+
16+
const test = (r: RegExp): ((c: string) => boolean) => r.test.bind(r);
17+
18+
export const wildcards: Matcher[] = [
19+
test(
20+
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m
21+
),
22+
test(/^(R|r)evert (.*)/),
23+
test(/^(fixup|squash)!/),
24+
isSemver,
25+
test(/^Merged (.*?)(in|into) (.*)/),
26+
test(/^Merge remote-tracking branch (.*)/),
27+
test(/^Automatic merge(.*)/),
28+
test(/^Auto-merged (.*?) into (.*)/)
29+
];

@commitlint/is-ignored/src/index.js

-45
This file was deleted.

@commitlint/is-ignored/src/index.test.js

-153
This file was deleted.

@commitlint/is-ignored/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './is-ignored';
2+
export {Matcher} from './defaults';

0 commit comments

Comments
 (0)