@fc3/eslint-plugin 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +673 -0
- package/README.md +61 -2
- package/bin/compile +55 -0
- package/bin/install +5 -0
- package/bin/lint +13 -0
- package/bin/postpublish +5 -0
- package/bin/precompile +55 -0
- package/bin/prepublish +8 -0
- package/bin/remap-paths +120 -0
- package/bin/test +9 -0
- package/bin/test-one +32 -0
- package/dist/.last-compile-time +1 -0
- package/dist/.last-publish-time +1 -0
- package/dist/src/config/recommended.d.ts +3 -0
- package/dist/src/config/recommended.js +73 -0
- package/dist/src/config/recommended.js.map +1 -0
- package/dist/src/constant/first-party-scope.d.ts +2 -0
- package/dist/src/constant/first-party-scope.js +5 -0
- package/dist/src/constant/first-party-scope.js.map +1 -0
- package/dist/src/enum/message-type.d.ts +7 -0
- package/dist/src/enum/message-type.js +11 -0
- package/dist/src/enum/message-type.js.map +1 -0
- package/dist/src/enum/module-type.d.ts +7 -0
- package/dist/src/enum/module-type.js +11 -0
- package/dist/src/enum/module-type.js.map +1 -0
- package/dist/src/import-formatter.d.ts +15 -0
- package/dist/src/import-formatter.js +52 -0
- package/dist/src/import-formatter.js.map +1 -0
- package/dist/src/import-sorter.d.ts +10 -0
- package/dist/src/import-sorter.js +27 -0
- package/dist/src/import-sorter.js.map +1 -0
- package/dist/src/import-validator.d.ts +30 -0
- package/dist/src/import-validator.js +159 -0
- package/dist/src/import-validator.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/module-classifier.d.ts +15 -0
- package/dist/src/module-classifier.js +67 -0
- package/dist/src/module-classifier.js.map +1 -0
- package/dist/src/plugin.d.ts +8 -0
- package/dist/src/plugin.js +23 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/rule/import-order.d.ts +6 -0
- package/dist/src/rule/import-order.js +56 -0
- package/dist/src/rule/import-order.js.map +1 -0
- package/dist/src/type/validation-error.d.ts +4 -0
- package/dist/src/type/validation-error.js +3 -0
- package/dist/src/type/validation-error.js.map +1 -0
- package/dist/src/utility/compare-import-order.d.ts +4 -0
- package/dist/src/utility/compare-import-order.js +30 -0
- package/dist/src/utility/compare-import-order.js.map +1 -0
- package/dist/src/utility/determine-import-module-type.d.ts +4 -0
- package/dist/src/utility/determine-import-module-type.js +12 -0
- package/dist/src/utility/determine-import-module-type.js.map +1 -0
- package/dist/src/utility/get-import-specifier-length.d.ts +3 -0
- package/dist/src/utility/get-import-specifier-length.js +22 -0
- package/dist/src/utility/get-import-specifier-length.js.map +1 -0
- package/dist/src/utility/get-module-type-label.d.ts +3 -0
- package/dist/src/utility/get-module-type-label.js +22 -0
- package/dist/src/utility/get-module-type-label.js.map +1 -0
- package/package.json +46 -5
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fc3/eslint-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Custom ESLint rules and the shared lint configuration for `@fc3` projects.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install the plugin alongside ESLint:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install --save-dev eslint @fc3/eslint-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then make it your `eslint.config.mjs`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import FC3 from '@fc3/eslint-plugin';
|
|
17
|
+
|
|
18
|
+
export default FC3.configs.recommended;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The recommended config bundles `@eslint/js` recommended, `typescript-eslint`
|
|
22
|
+
recommended, `eslint-config-prettier`, the shared naming and unused-variable
|
|
23
|
+
rules used across `@fc3` projects, and every rule in this plugin. To use only
|
|
24
|
+
the rules, register the plugin yourself:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import FC3 from '@fc3/eslint-plugin';
|
|
28
|
+
|
|
29
|
+
export default [
|
|
30
|
+
{
|
|
31
|
+
plugins: {'@fc3': FC3},
|
|
32
|
+
rules: {'@fc3/import-order': 'error'}
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Rules
|
|
38
|
+
|
|
39
|
+
### `@fc3/import-order`
|
|
40
|
+
|
|
41
|
+
Imports at the top of a file must be grouped, in this order:
|
|
42
|
+
|
|
43
|
+
1. Node core modules (`fs`, `path`, `node:http`)
|
|
44
|
+
2. Third-party modules (`eslint`, `formidable`)
|
|
45
|
+
3. First-party modules (anything under `@fc3`)
|
|
46
|
+
4. Local modules, resolved against `src/` from the project root
|
|
47
|
+
|
|
48
|
+
Each group is separated from the next by exactly one blank line. Within a
|
|
49
|
+
group, imports are sorted by the length of their specifiers, so that the
|
|
50
|
+
imported names form an ascending staircase. Local imports must use the
|
|
51
|
+
project's `baseUrl` style absolute path rather than a relative one.
|
|
52
|
+
|
|
53
|
+
The rule is auto-fixable: `eslint --fix` rewrites the whole import block into
|
|
54
|
+
the expected order.
|
|
55
|
+
|
|
56
|
+
## Development
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
npm install
|
|
60
|
+
./bin/test
|
|
61
|
+
./bin/lint
|
|
62
|
+
```
|
package/bin/compile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
if [[ $1 == '--help' ]]; then
|
|
4
|
+
echo "Triggers recompilation of the source code for the current project."
|
|
5
|
+
echo "Supported flags:"
|
|
6
|
+
echo "--force : Bypasses any precompilation checks (cache, mutex, etc)"
|
|
7
|
+
echo " Use this if you want to recompile no matter what."
|
|
8
|
+
echo " "
|
|
9
|
+
exit 0
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
if [[ $1 != '--force' ]]; then
|
|
13
|
+
./bin/precompile
|
|
14
|
+
|
|
15
|
+
case $? in
|
|
16
|
+
1)
|
|
17
|
+
exit 1
|
|
18
|
+
;;
|
|
19
|
+
3)
|
|
20
|
+
exit 0
|
|
21
|
+
;;
|
|
22
|
+
esac
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "Recompiling..."
|
|
26
|
+
mkdir -p dist
|
|
27
|
+
echo $$ > dist/.compile-lock
|
|
28
|
+
rm -f dist/.last-compile-time
|
|
29
|
+
|
|
30
|
+
project_dir="$(dirname $(dirname "$0"))"
|
|
31
|
+
|
|
32
|
+
if [[ $1 == '--force' ]]; then
|
|
33
|
+
rm -rf dist/src
|
|
34
|
+
rm -rf dist/test
|
|
35
|
+
./node_modules/.bin/tsc --declaration --project "$project_dir/config/tsconfig.json"
|
|
36
|
+
else
|
|
37
|
+
./node_modules/.bin/tsc --declaration --incremental --project "$project_dir/config/tsconfig.json"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
exit_status=$?
|
|
41
|
+
|
|
42
|
+
if [[ $exit_status -eq 0 ]]; then
|
|
43
|
+
./bin/remap-paths
|
|
44
|
+
echo $(date +%s) > dist/.last-compile-time
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
pid=$(cat dist/.compile-lock)
|
|
48
|
+
|
|
49
|
+
if [[ $pid == $$ ]]; then
|
|
50
|
+
rm dist/.compile-lock
|
|
51
|
+
exit $exit_status
|
|
52
|
+
else
|
|
53
|
+
echo "Detected a conflicting compile lock..."
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
package/bin/install
ADDED
package/bin/lint
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
./bin/compile
|
|
6
|
+
|
|
7
|
+
if [[ "${1:-}" == "--fix" ]]; then
|
|
8
|
+
./node_modules/.bin/eslint src test/unit --fix
|
|
9
|
+
./node_modules/.bin/prettier --write "src/**/*.ts" "test/unit/**/*.ts"
|
|
10
|
+
else
|
|
11
|
+
./node_modules/.bin/eslint src test/unit
|
|
12
|
+
./node_modules/.bin/prettier --check "src/**/*.ts" "test/unit/**/*.ts"
|
|
13
|
+
fi
|
package/bin/postpublish
ADDED
package/bin/precompile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
mkdir -p dist
|
|
4
|
+
|
|
5
|
+
if [ -f dist/.compile-lock ]; then
|
|
6
|
+
pid=$(cat dist/.compile-lock)
|
|
7
|
+
ticks=0
|
|
8
|
+
max_ticks=10
|
|
9
|
+
|
|
10
|
+
if ! ps -p $pid > /dev/null; then
|
|
11
|
+
echo "Detected a stale compile lock; deleting..."
|
|
12
|
+
rm -f dist/.compile-lock
|
|
13
|
+
else
|
|
14
|
+
echo "Compilation already in progress; waiting up to $max_ticks seconds..."
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
while [ -f dist/.compile-lock ]; do
|
|
18
|
+
sleep 1
|
|
19
|
+
let ticks=ticks+1
|
|
20
|
+
|
|
21
|
+
if [ $ticks -ge $max_ticks ]; then
|
|
22
|
+
echo "Timed out waiting for compilation to clear"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
done
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
if [[ -f ./dist/.last-publish-time ]]; then
|
|
29
|
+
echo "Found publication compile artifact; skipping recompilation."
|
|
30
|
+
exit 3
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
if [ -f dist/.last-compile-time ]; then
|
|
34
|
+
if [ ! -d src ]; then
|
|
35
|
+
# TODO: Confirm we're within a deploy environment
|
|
36
|
+
echo "src folder does not exist; skipping recompilation."
|
|
37
|
+
exit 3
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
typeset -i last_modification_time=$(find src test -type f -print0 |
|
|
41
|
+
xargs -0 stat -c "%X %N" |
|
|
42
|
+
sort -rn |
|
|
43
|
+
head -1 |
|
|
44
|
+
awk '{ print $1 }')
|
|
45
|
+
|
|
46
|
+
typeset -i last_compile_time=$(cat dist/.last-compile-time)
|
|
47
|
+
|
|
48
|
+
if (( $last_compile_time > $last_modification_time )); then
|
|
49
|
+
echo "No changes since last compile; skipping recompilation."
|
|
50
|
+
exit 3
|
|
51
|
+
fi
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# Compilation should occur.
|
|
55
|
+
exit 0
|
package/bin/prepublish
ADDED
package/bin/remap-paths
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const FS = require('fs');
|
|
4
|
+
const Path = require('path');
|
|
5
|
+
|
|
6
|
+
const JAVASCRIPT_EXTENSION = '.js';
|
|
7
|
+
const DECLARATION_EXTENSION = '.d.ts';
|
|
8
|
+
const UTF8_ENCODING = 'utf8';
|
|
9
|
+
const DIST_PATH = Path.resolve(__dirname, '../dist');
|
|
10
|
+
|
|
11
|
+
function processDirectory(directoryPath) {
|
|
12
|
+
const children = FS.readdirSync(directoryPath);
|
|
13
|
+
|
|
14
|
+
children.forEach(function each(child) {
|
|
15
|
+
// Ignore hidden files.
|
|
16
|
+
if (child[0] === '.') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const
|
|
21
|
+
childPath = Path.resolve(directoryPath, child),
|
|
22
|
+
parsedPath = Path.parse(childPath);
|
|
23
|
+
|
|
24
|
+
if (!parsedPath.ext) {
|
|
25
|
+
processDirectory(childPath);
|
|
26
|
+
} else if (parsedPath.ext === JAVASCRIPT_EXTENSION) {
|
|
27
|
+
processSourceFile(childPath);
|
|
28
|
+
} else if (childPath.slice(-5) === DECLARATION_EXTENSION) {
|
|
29
|
+
processDeclarationFile(childPath);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function processSourceFile(filePath) {
|
|
35
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
36
|
+
|
|
37
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
38
|
+
return line.replace(/require\("([^"]+)/g, function replacer(match, path) {
|
|
39
|
+
if (path[0] === '.') {
|
|
40
|
+
return match;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let dependencyPath = DIST_PATH + '/src/' + path + '.js';
|
|
44
|
+
|
|
45
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
46
|
+
// Fall back to checking whether there's an index.js in a directory
|
|
47
|
+
// of this name, instead of a toplevel .js source file directly.
|
|
48
|
+
dependencyPath = DIST_PATH + '/src/' + path + '/index.js';
|
|
49
|
+
|
|
50
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
51
|
+
// Well, we tried.
|
|
52
|
+
return match;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parsedFile = Path.parse(filePath);
|
|
57
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
58
|
+
|
|
59
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
60
|
+
|
|
61
|
+
if (relativeDirectory === '') {
|
|
62
|
+
relativeDirectory = '.';
|
|
63
|
+
} else {
|
|
64
|
+
relativeDirectory = './' + relativeDirectory;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
68
|
+
|
|
69
|
+
return 'require("' + relativePath;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function processDeclarationFile(filePath) {
|
|
77
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
78
|
+
|
|
79
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
80
|
+
return line.replace(/from '([^']+)/g, function replacer(match, path) {
|
|
81
|
+
if (path[0] === '.') {
|
|
82
|
+
return match;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let dependencyPath = DIST_PATH + '/src/' + path + '.d.ts';
|
|
86
|
+
|
|
87
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
88
|
+
// Fall back to checking whether there's an index.js in a directory
|
|
89
|
+
// of this name, instead of a toplevel .d.ts source file directly.
|
|
90
|
+
dependencyPath = DIST_PATH + '/src/' + path + '/index.d.ts';
|
|
91
|
+
|
|
92
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
93
|
+
// Well, we tried.
|
|
94
|
+
return match;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const parsedFile = Path.parse(filePath);
|
|
99
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
100
|
+
|
|
101
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
102
|
+
|
|
103
|
+
if (relativeDirectory === '') {
|
|
104
|
+
relativeDirectory = '.';
|
|
105
|
+
} else {
|
|
106
|
+
relativeDirectory = './' + relativeDirectory;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
110
|
+
|
|
111
|
+
relativePath = relativePath.replace(DECLARATION_EXTENSION, '');
|
|
112
|
+
|
|
113
|
+
return "from '" + relativePath;
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
processDirectory('./dist', 0);
|
package/bin/test
ADDED
package/bin/test-one
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
RED='\033[0;31m'
|
|
6
|
+
YELLOW='\033[0;33m'
|
|
7
|
+
RESET='\033[0m'
|
|
8
|
+
|
|
9
|
+
bin/compile
|
|
10
|
+
|
|
11
|
+
FILE_TO_TEST=$1
|
|
12
|
+
|
|
13
|
+
if [ -f "dist/$1.js" ]; then
|
|
14
|
+
TEST_FILEPATH="$FILE_TO_TEST.js"
|
|
15
|
+
else
|
|
16
|
+
# If someone enters the path to the corresponding Typescript file for a test,
|
|
17
|
+
# we should map this to the associated JS file in the dist/test directory:
|
|
18
|
+
FILE_WITH_CORRECTED_EXTENSION=${FILE_TO_TEST/.ts/.js}
|
|
19
|
+
|
|
20
|
+
if [ -f "dist/$FILE_WITH_CORRECTED_EXTENSION" ]; then
|
|
21
|
+
TEST_FILEPATH=$FILE_WITH_CORRECTED_EXTENSION
|
|
22
|
+
fi
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
if [ -f "dist/$TEST_FILEPATH" ]; then
|
|
26
|
+
NODE_ENV=test node --test dist/$TEST_FILEPATH
|
|
27
|
+
else
|
|
28
|
+
echo ""
|
|
29
|
+
echo -e "${RED}[ERROR]${RESET} No test file(s) found matching '$1'"
|
|
30
|
+
echo -e "${YELLOW}Example:${RESET} dev test test/unit/logger"
|
|
31
|
+
echo ""
|
|
32
|
+
fi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1792408598
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1792410504
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const js_1 = __importDefault(require("@eslint/js"));
|
|
7
|
+
const typescript_eslint_1 = __importDefault(require("typescript-eslint"));
|
|
8
|
+
const flat_1 = __importDefault(require("eslint-config-prettier/flat"));
|
|
9
|
+
const IGNORED_PATHS = ['dist/', 'node_modules/'];
|
|
10
|
+
const UNUSED_VARIABLE_OPTIONS = {
|
|
11
|
+
argsIgnorePattern: '^_',
|
|
12
|
+
varsIgnorePattern: '^_',
|
|
13
|
+
caughtErrors: 'all',
|
|
14
|
+
caughtErrorsIgnorePattern: '^_',
|
|
15
|
+
destructuredArrayIgnorePattern: '^_',
|
|
16
|
+
ignoreRestSiblings: true
|
|
17
|
+
};
|
|
18
|
+
const NAMING_CONVENTIONS = [
|
|
19
|
+
{
|
|
20
|
+
selector: 'property',
|
|
21
|
+
modifiers: ['requiresQuotes'],
|
|
22
|
+
format: null
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
selector: 'property',
|
|
26
|
+
format: ['snake_case', 'UPPER_CASE']
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
selector: 'variable',
|
|
30
|
+
format: ['snake_case', 'PascalCase', 'UPPER_CASE'],
|
|
31
|
+
leadingUnderscore: 'allowSingleOrDouble',
|
|
32
|
+
trailingUnderscore: 'forbid'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
selector: 'function',
|
|
36
|
+
format: ['camelCase']
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
selector: 'typeLike',
|
|
40
|
+
format: ['PascalCase']
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
selector: 'method',
|
|
44
|
+
format: ['camelCase']
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
selector: 'parameter',
|
|
48
|
+
format: ['snake_case'],
|
|
49
|
+
leadingUnderscore: 'allowSingleOrDouble'
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
function buildRecommendedConfig(plugin) {
|
|
53
|
+
return typescript_eslint_1.default.config({
|
|
54
|
+
ignores: IGNORED_PATHS
|
|
55
|
+
}, js_1.default.configs.recommended, typescript_eslint_1.default.configs.recommended, flat_1.default, {
|
|
56
|
+
plugins: {
|
|
57
|
+
'@fc3': plugin
|
|
58
|
+
},
|
|
59
|
+
rules: {
|
|
60
|
+
'no-control-regex': 'off',
|
|
61
|
+
'no-case-declarations': 'off',
|
|
62
|
+
'no-unused-labels': 'off',
|
|
63
|
+
'@typescript-eslint/no-unused-vars': ['error', UNUSED_VARIABLE_OPTIONS],
|
|
64
|
+
'@typescript-eslint/naming-convention': [
|
|
65
|
+
'error',
|
|
66
|
+
...NAMING_CONVENTIONS
|
|
67
|
+
],
|
|
68
|
+
'@fc3/import-order': 'error'
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.default = buildRecommendedConfig;
|
|
73
|
+
//# sourceMappingURL=recommended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../../src/config/recommended.ts"],"names":[],"mappings":";;;;;AAAA,oDAAgC;AAChC,0EAAyC;AAEzC,uEAAyD;AAEzD,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAEjD,MAAM,uBAAuB,GAAG;IAC/B,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,YAAY,EAAE,KAAK;IACnB,yBAAyB,EAAE,IAAI;IAC/B,8BAA8B,EAAE,IAAI;IACpC,kBAAkB,EAAE,IAAI;CACxB,CAAC;AAEF,MAAM,kBAAkB,GAAG;IAC1B;QACC,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,CAAC,gBAAgB,CAAC;QAC7B,MAAM,EAAE,IAAI;KACZ;IACD;QACC,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;KACpC;IACD;QACC,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;QAClD,iBAAiB,EAAE,qBAAqB;QACxC,kBAAkB,EAAE,QAAQ;KAC5B;IACD;QACC,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC,WAAW,CAAC;KACrB;IACD;QACC,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC,YAAY,CAAC;KACtB;IACD;QACC,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,CAAC,WAAW,CAAC;KACrB;IACD;QACC,QAAQ,EAAE,WAAW;QACrB,MAAM,EAAE,CAAC,YAAY,CAAC;QACtB,iBAAiB,EAAE,qBAAqB;KACxC;CACD,CAAC;AAEF,SAAS,sBAAsB,CAC9B,MAAkC;IAElC,OAAO,2BAAQ,CAAC,MAAM,CACrB;QACC,OAAO,EAAE,aAAa;KACtB,EACD,YAAM,CAAC,OAAO,CAAC,WAAW,EAC1B,2BAAQ,CAAC,OAAO,CAAC,WAAW,EAC5B,cAAc,EACd;QACC,OAAO,EAAE;YACR,MAAM,EAAE,MAAM;SACd;QACD,KAAK,EAAE;YACN,kBAAkB,EAAE,KAAK;YACzB,sBAAsB,EAAE,KAAK;YAC7B,kBAAkB,EAAE,KAAK;YACzB,mCAAmC,EAAE,CAAC,OAAO,EAAE,uBAAuB,CAAC;YACvE,sCAAsC,EAAE;gBACvC,OAAO;gBACP,GAAG,kBAAkB;aACrB;YACD,mBAAmB,EAAE,OAAO;SAC5B;KACD,CACD,CAAC;AACH,CAAC;AAED,kBAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-party-scope.js","sourceRoot":"","sources":["../../../src/constant/first-party-scope.ts"],"names":[],"mappings":";;AAAA,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var MessageType;
|
|
4
|
+
(function (MessageType) {
|
|
5
|
+
MessageType["IMPORT_LENGTH_ORDER"] = "import_length_order";
|
|
6
|
+
MessageType["IMPORT_TYPE_ORDER"] = "import_type_order";
|
|
7
|
+
MessageType["MISSING_NEWLINE"] = "missing_newline";
|
|
8
|
+
MessageType["NON_ABSOLUTE_PATH"] = "non_absolute_path";
|
|
9
|
+
})(MessageType || (MessageType = {}));
|
|
10
|
+
exports.default = MessageType;
|
|
11
|
+
//# sourceMappingURL=message-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-type.js","sourceRoot":"","sources":["../../../src/enum/message-type.ts"],"names":[],"mappings":";;AAAA,IAAK,WAKJ;AALD,WAAK,WAAW;IACf,0DAA2C,CAAA;IAC3C,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;IACnC,sDAAuC,CAAA;AACxC,CAAC,EALI,WAAW,KAAX,WAAW,QAKf;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ModuleType;
|
|
4
|
+
(function (ModuleType) {
|
|
5
|
+
ModuleType[ModuleType["CORE"] = 0] = "CORE";
|
|
6
|
+
ModuleType[ModuleType["THIRD_PARTY"] = 1] = "THIRD_PARTY";
|
|
7
|
+
ModuleType[ModuleType["FIRST_PARTY"] = 2] = "FIRST_PARTY";
|
|
8
|
+
ModuleType[ModuleType["LOCAL"] = 3] = "LOCAL";
|
|
9
|
+
})(ModuleType || (ModuleType = {}));
|
|
10
|
+
exports.default = ModuleType;
|
|
11
|
+
//# sourceMappingURL=module-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-type.js","sourceRoot":"","sources":["../../../src/enum/module-type.ts"],"names":[],"mappings":";;AAAA,IAAK,UAKJ;AALD,WAAK,UAAU;IACd,2CAAQ,CAAA;IACR,yDAAe,CAAA;IACf,yDAAe,CAAA;IACf,6CAAS,CAAA;AACV,CAAC,EALI,UAAU,KAAV,UAAU,QAKd;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
declare class ImportFormatter {
|
|
3
|
+
private root_directory;
|
|
4
|
+
private source_text;
|
|
5
|
+
private imports;
|
|
6
|
+
constructor(root_directory: string, source_text: string, imports: TSESTree.ImportDeclaration[]);
|
|
7
|
+
format(): string;
|
|
8
|
+
private getSeparator;
|
|
9
|
+
private getModuleType;
|
|
10
|
+
private getImportContent;
|
|
11
|
+
private getSourceText;
|
|
12
|
+
private getImports;
|
|
13
|
+
private getRootDirectory;
|
|
14
|
+
}
|
|
15
|
+
export default ImportFormatter;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const import_sorter_1 = __importDefault(require("./import-sorter.js"));
|
|
7
|
+
const determine_import_module_type_1 = __importDefault(require("./utility/determine-import-module-type.js"));
|
|
8
|
+
class ImportFormatter {
|
|
9
|
+
constructor(root_directory, source_text, imports) {
|
|
10
|
+
this.root_directory = root_directory;
|
|
11
|
+
this.source_text = source_text;
|
|
12
|
+
const sorter = new import_sorter_1.default(root_directory, imports);
|
|
13
|
+
this.imports = sorter.sort();
|
|
14
|
+
}
|
|
15
|
+
format() {
|
|
16
|
+
const imports = this.getImports();
|
|
17
|
+
const formatted_imports = imports.map((current_import, index) => {
|
|
18
|
+
const previous_import = imports[index - 1];
|
|
19
|
+
const separator = this.getSeparator(current_import, previous_import);
|
|
20
|
+
const content = this.getImportContent(current_import);
|
|
21
|
+
return `${separator}${content}`;
|
|
22
|
+
});
|
|
23
|
+
return formatted_imports.join('\n');
|
|
24
|
+
}
|
|
25
|
+
getSeparator(current_import, previous_import) {
|
|
26
|
+
if (previous_import === undefined) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
const current_type = this.getModuleType(current_import);
|
|
30
|
+
const previous_type = this.getModuleType(previous_import);
|
|
31
|
+
return current_type === previous_type ? '' : '\n';
|
|
32
|
+
}
|
|
33
|
+
getModuleType(import_declaration) {
|
|
34
|
+
const root_directory = this.getRootDirectory();
|
|
35
|
+
return (0, determine_import_module_type_1.default)(root_directory, import_declaration);
|
|
36
|
+
}
|
|
37
|
+
getImportContent(import_declaration) {
|
|
38
|
+
const [start, end] = import_declaration.range;
|
|
39
|
+
return this.getSourceText().slice(start, end);
|
|
40
|
+
}
|
|
41
|
+
getSourceText() {
|
|
42
|
+
return this.source_text;
|
|
43
|
+
}
|
|
44
|
+
getImports() {
|
|
45
|
+
return this.imports;
|
|
46
|
+
}
|
|
47
|
+
getRootDirectory() {
|
|
48
|
+
return this.root_directory;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = ImportFormatter;
|
|
52
|
+
//# sourceMappingURL=import-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-formatter.js","sourceRoot":"","sources":["../../src/import-formatter.ts"],"names":[],"mappings":";;;;;AAGA,kEAAyC;AACzC,wGAA6E;AAE7E,MAAM,eAAe;IAKpB,YACC,cAAsB,EACtB,WAAmB,EACnB,OAAqC;QAErC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,MAAM,MAAM,GAAG,IAAI,uBAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAEzD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;IAEM,MAAM;QACZ,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,KAAK,EAAE,EAAE;YAC/D,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;YAEtD,OAAO,GAAG,SAAS,GAAG,OAAO,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,YAAY,CACnB,cAA0C,EAC1C,eAAuD;QAEvD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YACnC,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QAE1D,OAAO,YAAY,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;IAEO,aAAa,CACpB,kBAA8C;QAE9C,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE/C,OAAO,IAAA,sCAAyB,EAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IACtE,CAAC;IAEO,gBAAgB,CACvB,kBAA8C;QAE9C,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC;QAE9C,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;IAEO,aAAa;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAEO,UAAU;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEO,gBAAgB;QACvB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
declare class ImportSorter {
|
|
3
|
+
private root_directory;
|
|
4
|
+
private imports;
|
|
5
|
+
constructor(root_directory: string, imports: TSESTree.ImportDeclaration[]);
|
|
6
|
+
sort(): TSESTree.ImportDeclaration[];
|
|
7
|
+
private getImports;
|
|
8
|
+
private getRootDirectory;
|
|
9
|
+
}
|
|
10
|
+
export default ImportSorter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const compare_import_order_1 = __importDefault(require("./utility/compare-import-order.js"));
|
|
7
|
+
class ImportSorter {
|
|
8
|
+
constructor(root_directory, imports) {
|
|
9
|
+
this.root_directory = root_directory;
|
|
10
|
+
this.imports = imports;
|
|
11
|
+
}
|
|
12
|
+
sort() {
|
|
13
|
+
const root_directory = this.getRootDirectory();
|
|
14
|
+
const imports = [...this.getImports()];
|
|
15
|
+
return imports.sort((a, b) => {
|
|
16
|
+
return (0, compare_import_order_1.default)(root_directory, a, b);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
getImports() {
|
|
20
|
+
return this.imports;
|
|
21
|
+
}
|
|
22
|
+
getRootDirectory() {
|
|
23
|
+
return this.root_directory;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = ImportSorter;
|
|
27
|
+
//# sourceMappingURL=import-sorter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-sorter.js","sourceRoot":"","sources":["../../src/import-sorter.ts"],"names":[],"mappings":";;;;;AAEA,wFAA8D;AAE9D,MAAM,YAAY;IAIjB,YACC,cAAsB,EACtB,OAAqC;QAErC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEM,IAAI;QACV,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAEvC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5B,OAAO,IAAA,8BAAkB,EAAC,cAAc,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,UAAU;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEO,gBAAgB;QACvB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,kBAAe,YAAY,CAAC"}
|