Skip to content

Commit d665a1a

Browse files
committed
refactor: migrate cmj to esm
1 parent a129dfb commit d665a1a

30 files changed

+279
-372
lines changed

.eslintrc.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

.eslintrc.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"ecmaVersion": "latest",
5+
"sourceType": "module"
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:eslint-plugin/recommended",
10+
"plugin:node/recommended",
11+
"prettier",
12+
"plugin:jsdoc/recommended"
13+
],
14+
"plugins": ["prettier", "jsdoc"],
15+
"rules": {
16+
"prettier/prettier": [
17+
"error",
18+
{
19+
"endOfLine": "auto"
20+
}
21+
]
22+
},
23+
"env": {
24+
"node": true
25+
},
26+
"overrides": [
27+
{
28+
"files": ["tests/**/*.js"],
29+
"env": { "mocha": true }
30+
}
31+
],
32+
"settings": {
33+
"jsdoc": {
34+
"mode": "typescript"
35+
}
36+
}
37+
}

jsconfig.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
22
"compilerOptions": {
33
"checkJs": true,
4-
"target": "es2015",
4+
"target": "es2017",
5+
"module": "node16"
56
},
6-
"exclude": [
7-
"node_modules",
8-
".nyc_output",
9-
".idea",
10-
".vscode",
11-
".github",
12-
".husky",
13-
"docs",
14-
]
7+
"include": ["lib", "tests"]
158
}

lib/constants/message.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,35 @@
22
* @file Message templates
33
* @author Huan Luo
44
*/
5-
'use strict';
65

7-
const { template } = require('../utils/utility');
6+
import { template } from '../utils/utility.js';
87

9-
const NAMING_PATTERN_OBJECT_ERROR_MESSAGE = template(
8+
export const NAMING_PATTERN_OBJECT_ERROR_MESSAGE = template(
109
'The naming pattern object "$0" does not appear to be an Object type, please double-check it and try again'
1110
);
1211

13-
const PATTERN_ERROR_MESSAGE = template(
12+
export const PATTERN_ERROR_MESSAGE = template(
1413
'There is an invalid pattern "$0", please double-check it and try again'
1514
);
1615

17-
const PREFINED_MATCH_SYNTAX_ERROR_MESSAGE = template(
16+
export const PREFINED_MATCH_SYNTAX_ERROR_MESSAGE = template(
1817
'The prefined match "$0" is not found in the pattern "$1", please double-check it and try again'
1918
);
2019

21-
const FILENAME_BLOCKLIST_ERROR_MESSAGE = template(
20+
export const FILENAME_BLOCKLIST_ERROR_MESSAGE = template(
2221
'The filename "$0" matches the blocklisted "$1" pattern, use a pattern like "$2" instead'
2322
);
2423

25-
const FILENAME_NAMING_CONVENTION_ERROR_MESSAGE = template(
24+
export const FILENAME_NAMING_CONVENTION_ERROR_MESSAGE = template(
2625
'The filename "$0" does not match the "$1" pattern'
2726
);
2827

29-
const FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE = template(
28+
export const FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE = template(
3029
'The folder of the file "$0" does not match the "$1" pattern'
3130
);
3231

33-
const FOLDER_NAMING_CONVENTION_ERROR_MESSAGE = template(
32+
export const FOLDER_NAMING_CONVENTION_ERROR_MESSAGE = template(
3433
'The folder "$0" does not match the "$1" pattern'
3534
);
3635

37-
const NO_INDEX_ERROR_MESSAGE = 'The filename "index" is not allowed';
38-
39-
module.exports = {
40-
NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
41-
PATTERN_ERROR_MESSAGE,
42-
PREFINED_MATCH_SYNTAX_ERROR_MESSAGE,
43-
FILENAME_BLOCKLIST_ERROR_MESSAGE,
44-
FILENAME_NAMING_CONVENTION_ERROR_MESSAGE,
45-
FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE,
46-
FOLDER_NAMING_CONVENTION_ERROR_MESSAGE,
47-
NO_INDEX_ERROR_MESSAGE,
48-
};
36+
export const NO_INDEX_ERROR_MESSAGE = 'The filename "index" is not allowed';

lib/constants/naming-convention.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,33 @@
22
* @file Built in filename naming convention
33
* @author Huan Luo
44
*/
5-
'use strict';
65

76
/**
87
* @example hello, helloWorld
98
*/
10-
const CAMEL_CASE = '+([a-z])*([a-z0-9])*([A-Z]*([a-z0-9]))';
9+
export const CAMEL_CASE = '+([a-z])*([a-z0-9])*([A-Z]*([a-z0-9]))';
1110

1211
/**
1312
* @example Hello, HelloWorld
1413
*/
15-
const PASCAL_CASE = '*([A-Z]*([a-z0-9]))';
14+
export const PASCAL_CASE = '*([A-Z]*([a-z0-9]))';
1615

1716
/**
1817
* @example hello, hello_world
1918
*/
20-
const SNAKE_CASE = '+([a-z])*([a-z0-9])*(_+([a-z0-9]))';
19+
export const SNAKE_CASE = '+([a-z])*([a-z0-9])*(_+([a-z0-9]))';
2120

2221
/**
2322
* @example hello, hello-world
2423
*/
25-
const KEBAB_CASE = '+([a-z])*([a-z0-9])*(-+([a-z0-9]))';
24+
export const KEBAB_CASE = '+([a-z])*([a-z0-9])*(-+([a-z0-9]))';
2625

2726
/**
2827
* @example HELLO, HELLO_WORLD
2928
*/
30-
const SCREAMING_SNAKE_CASE = '+([A-Z])*([A-Z0-9])*(_+([A-Z0-9]))';
29+
export const SCREAMING_SNAKE_CASE = '+([A-Z])*([A-Z0-9])*(_+([A-Z0-9]))';
3130

3231
/**
3332
* @example hello, helloworld
3433
*/
35-
const FLAT_CASE = '+([a-z0-9])';
36-
37-
module.exports = {
38-
CAMEL_CASE,
39-
PASCAL_CASE,
40-
SNAKE_CASE,
41-
KEBAB_CASE,
42-
SCREAMING_SNAKE_CASE,
43-
FLAT_CASE,
44-
};
34+
export const FLAT_CASE = '+([a-z0-9])';

lib/constants/next-js-naming-convention.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
* @file Built in next js app router naming convention
33
* @author Huan Luo
44
*/
5-
'use strict';
65

7-
const { CAMEL_CASE, KEBAB_CASE } = require('./naming-convention');
6+
import { CAMEL_CASE, KEBAB_CASE } from './naming-convention.js';
87

98
/**
109
* @example [helpPageId]
@@ -34,8 +33,4 @@ const NEXT_JS_NAMED_SLOTS = `\\@${KEBAB_CASE}`;
3433
/**
3534
* @example app, [helpPageId], [...auth], [[...auth]], (auth), \@feed
3635
*/
37-
const NEXT_JS_APP_ROUTER_CASE = `@(${KEBAB_CASE}|${NEXT_JS_DYNAMIC_SEGMENTS}|${NEXT_JS_CATCH_ALL_SEGMENTS}|${NEXT_JS_OPTIONAL_CATCH_ALL_SEGMENTS}|${NEXT_JS_ROUTE_GROUPS}|${NEXT_JS_NAMED_SLOTS})`;
38-
39-
module.exports = {
40-
NEXT_JS_APP_ROUTER_CASE,
41-
};
36+
export const NEXT_JS_APP_ROUTER_CASE = `@(${KEBAB_CASE}|${NEXT_JS_DYNAMIC_SEGMENTS}|${NEXT_JS_CATCH_ALL_SEGMENTS}|${NEXT_JS_OPTIONAL_CATCH_ALL_SEGMENTS}|${NEXT_JS_ROUTE_GROUPS}|${NEXT_JS_NAMED_SLOTS})`;

lib/constants/regex.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@
22
* @file Regex pattern constants
33
* @author Huan Luo
44
*/
5-
'use strict';
65

76
/**
87
* @example <1>
98
*/
10-
const PREFINED_MATCH_SYNTAX_REGEXP = /^<(\d+)>$/;
9+
export const PREFINED_MATCH_SYNTAX_REGEXP = /^<(\d+)>$/;
1110

1211
/**
1312
* @example C:\
1413
*/
15-
const WINDOWS_DRIVE_LETTER_REGEXP = /^[A-Za-z]:\\/;
14+
export const WINDOWS_DRIVE_LETTER_REGEXP = /^[A-Za-z]:\\/;
1615

1716
/**
1817
* @example $0
1918
*/
20-
const TEMPLATE_VARIABLE_REGEXP = /\$(\d*)/;
21-
22-
module.exports = {
23-
PREFINED_MATCH_SYNTAX_REGEXP,
24-
WINDOWS_DRIVE_LETTER_REGEXP,
25-
TEMPLATE_VARIABLE_REGEXP,
26-
};
19+
export const TEMPLATE_VARIABLE_REGEXP = /\$(\d*)/;

lib/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/**
2-
* @file check the file folder
2+
* @file Entry point for all rules
33
* @author Huan Luo
44
*/
5-
'use strict';
65

7-
const requireIndex = require('requireindex');
6+
import FilenameBlocklist from './rules/filename-blocklist.js';
7+
import FilenameNamingConvention from './rules/filename-naming-convention.js';
8+
import FolderMatchWithFex from './rules/folder-match-with-fex.js';
9+
import FolderNamingConvention from './rules/folder-naming-convention.js';
10+
import NoIndex from './rules/no-index.js';
811

9-
module.exports.rules = requireIndex(__dirname + '/rules');
12+
export const rules = {
13+
'filename-blocklist': FilenameBlocklist,
14+
'filename-naming-convention': FilenameNamingConvention,
15+
'folder-match-with-fex': FolderMatchWithFex,
16+
'folder-naming-convention': FolderNamingConvention,
17+
'no-index': NoIndex,
18+
};

lib/rules/filename-blocklist.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
* @file The filename should be blocklisted.
33
* @author Florian Ehmke, Huan Luo
44
*/
5-
'use strict';
65

7-
const { getFilename, getFilePath } = require('../utils/filename');
8-
const {
6+
import { FILENAME_BLOCKLIST_ERROR_MESSAGE } from '../constants/message.js';
7+
import { getDocUrl } from '../utils/doc.js';
8+
import { getFilePath, getFilename } from '../utils/filename.js';
9+
import { matchRule } from '../utils/rule.js';
10+
import {
911
validateNamingPatternObject,
1012
globPatternValidator,
11-
} = require('../utils/validation');
12-
const { getDocUrl } = require('../utils/doc');
13-
const { FILENAME_BLOCKLIST_ERROR_MESSAGE } = require('../constants/message');
14-
const { matchRule } = require('../utils/rule');
13+
} from '../utils/validation.js';
1514

1615
/**
1716
* @type {import('eslint').Rule.RuleModule}
1817
*/
19-
module.exports = {
18+
export default {
2019
meta: {
2120
type: 'layout',
2221
docs: {

lib/rules/filename-naming-convention.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@
22
* @file The filename should follow the filename naming convention
33
* @author Huan Luo
44
*/
5-
'use strict';
65

7-
const {
8-
transformRuleWithPrefinedMatchSyntax,
6+
import { FILENAME_NAMING_CONVENTION_ERROR_MESSAGE } from '../constants/message.js';
7+
import { getDocUrl } from '../utils/doc.js';
8+
import { getBasename, getFilePath, getFilename } from '../utils/filename.js';
9+
import {
910
matchRule,
10-
} = require('../utils/rule');
11-
const { getFilename, getBasename, getFilePath } = require('../utils/filename');
12-
const {
13-
validateNamingPatternObject,
11+
transformRuleWithPrefinedMatchSyntax,
12+
} from '../utils/rule.js';
13+
import {
1414
filenameNamingPatternValidator,
1515
globPatternValidator,
16-
} = require('../utils/validation');
17-
const { getDocUrl } = require('../utils/doc');
18-
const {
19-
FILENAME_NAMING_CONVENTION_ERROR_MESSAGE,
20-
} = require('../constants/message');
16+
validateNamingPatternObject,
17+
} from '../utils/validation.js';
2118

2219
/**
2320
* @type {import('eslint').Rule.RuleModule}
2421
*/
25-
module.exports = {
22+
export default {
2623
meta: {
2724
type: 'layout',
2825
docs: {

lib/rules/folder-match-with-fex.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
* @file The folder should match the naming pattern specified by its file
33
* @author Huan Luo
44
*/
5-
'use strict';
65

7-
const {
8-
getFolderPath,
9-
getFilename,
10-
getFilePath,
11-
} = require('../utils/filename');
12-
const {
13-
validateNamingPatternObject,
6+
import { FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE } from '../constants/message.js';
7+
import { getDocUrl } from '../utils/doc.js';
8+
import { getFilePath, getFilename, getFolderPath } from '../utils/filename.js';
9+
import { matchRule } from '../utils/rule.js';
10+
import {
1411
globPatternValidator,
15-
} = require('../utils/validation');
16-
const { getDocUrl } = require('../utils/doc');
17-
const { FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE } = require('../constants/message');
18-
const { matchRule } = require('../utils/rule');
12+
validateNamingPatternObject,
13+
} from '../utils/validation.js';
1914

2015
/**
2116
* @type {import('eslint').Rule.RuleModule}
2217
*/
23-
module.exports = {
18+
export default {
2419
meta: {
2520
type: 'layout',
2621
docs: {

0 commit comments

Comments
 (0)