eslint-plugin-julia 0.0.0-stage → 0.3.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/CHANGELOG.md +159 -0
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/data/base-core-exports.json +5 -0
- package/data/public-only.json +35 -0
- package/data/stdlib-exports.json +180 -0
- package/package.json +76 -4
- package/src/index.js +226 -0
- package/src/language.js +46 -0
- package/src/macro-signatures.js +277 -0
- package/src/module-resolution.js +1187 -0
- package/src/orphans.js +631 -0
- package/src/parser/flags.js +25 -0
- package/src/parser/green-tree.js +41 -0
- package/src/parser/positions.js +29 -0
- package/src/parser/syntax-tree.js +91 -0
- package/src/parser/wasm-host.js +92 -0
- package/src/resolver/index.js +232 -0
- package/src/resolver/pkg-child.mjs +165 -0
- package/src/resolver/toml.js +63 -0
- package/src/resolver/warm.mjs +26 -0
- package/src/rules/common.js +52 -0
- package/src/rules/correctness-common.js +90 -0
- package/src/rules/growth-common.js +93 -0
- package/src/rules/idiom-common.js +116 -0
- package/src/rules/no-collapsible-if.js +38 -0
- package/src/rules/no-collect-before-range-iteration.js +24 -0
- package/src/rules/no-compare-negative-zero.js +50 -0
- package/src/rules/no-concat-growth-in-loop.js +18 -0
- package/src/rules/no-cond-assign.js +126 -0
- package/src/rules/no-const-reassign.js +61 -0
- package/src/rules/no-constant-condition.js +59 -0
- package/src/rules/no-debugger.js +96 -0
- package/src/rules/no-discarded-copy-result.js +50 -0
- package/src/rules/no-dupe-args.js +25 -0
- package/src/rules/no-dupe-elseif.js +57 -0
- package/src/rules/no-duplicate-dict-keys.js +95 -0
- package/src/rules/no-duplicate-keyword-arguments.js +40 -0
- package/src/rules/no-duplicate-logical-operands.js +85 -0
- package/src/rules/no-duplicate-method-signatures.js +90 -0
- package/src/rules/no-duplicate-struct-fields.js +38 -0
- package/src/rules/no-empty-block.js +49 -0
- package/src/rules/no-empty-catch.js +32 -0
- package/src/rules/no-empty-literal-range.js +26 -0
- package/src/rules/no-env-mutation.js +62 -0
- package/src/rules/no-eval-local-symbol.js +85 -0
- package/src/rules/no-fill-with-mutable.js +43 -0
- package/src/rules/no-full-slice-in-consumer.js +41 -0
- package/src/rules/no-identical-branches.js +44 -0
- package/src/rules/no-import-assign.js +64 -0
- package/src/rules/no-impossible-length-comparison.js +49 -0
- package/src/rules/no-invalid-foreign-call-signature.js +58 -0
- package/src/rules/no-isdefined-local-call.js +23 -0
- package/src/rules/no-loss-of-float-integer-precision.js +41 -0
- package/src/rules/no-nothing-return-conversion.js +127 -0
- package/src/rules/no-obvious-type-piracy.js +112 -0
- package/src/rules/no-orphan-file.js +39 -0
- package/src/rules/no-overwritten-literal-index.js +80 -0
- package/src/rules/no-reassigned-capture.js +107 -0
- package/src/rules/no-redundant-type-assertion.js +36 -0
- package/src/rules/no-redundant-union-members.js +42 -0
- package/src/rules/no-restricted-calls.js +74 -0
- package/src/rules/no-restricted-imports.js +105 -0
- package/src/rules/no-restricted-macros.js +61 -0
- package/src/rules/no-self-assign.js +65 -0
- package/src/rules/no-self-identity-comparison.js +37 -0
- package/src/rules/no-shadowed-loop-var.js +83 -0
- package/src/rules/no-show-macro.js +90 -0
- package/src/rules/no-single-iteration-loop.js +50 -0
- package/src/rules/no-string-growth-in-loop.js +18 -0
- package/src/rules/no-throw-literal.js +33 -0
- package/src/rules/no-unbound-type-parameters.js +91 -0
- package/src/rules/no-undef.js +284 -0
- package/src/rules/no-undefined-exports.js +60 -0
- package/src/rules/no-uninitialized-ref-read.js +38 -0
- package/src/rules/no-unreachable.js +82 -0
- package/src/rules/no-unsafe-finally.js +35 -0
- package/src/rules/no-unsafe-negation.js +77 -0
- package/src/rules/no-unused-expressions.js +137 -0
- package/src/rules/no-unused-type-parameters.js +55 -0
- package/src/rules/no-unused-vars.js +123 -0
- package/src/rules/no-use-before-define.js +139 -0
- package/src/rules/no-useless-assignment.js +75 -0
- package/src/rules/no-useless-catch.js +28 -0
- package/src/rules/parse-errors.js +19 -0
- package/src/rules/performance-common.js +119 -0
- package/src/rules/prefer-any.js +75 -0
- package/src/rules/prefer-const-global.js +103 -0
- package/src/rules/prefer-count-over-findall-length.js +46 -0
- package/src/rules/prefer-eachindex.js +120 -0
- package/src/rules/prefer-extreme-over-sort.js +73 -0
- package/src/rules/prefer-generator-sum.js +34 -0
- package/src/rules/prefer-identity-nothing.js +43 -0
- package/src/rules/prefer-in.js +67 -0
- package/src/rules/prefer-isa.js +70 -0
- package/src/rules/prefer-isempty.js +57 -0
- package/src/rules/prefer-ismissing.js +42 -0
- package/src/rules/prefer-parenthesized-interpolation.js +160 -0
- package/src/rules/prefer-size-dimension.js +19 -0
- package/src/rules/prefer-sized-push-buffer.js +81 -0
- package/src/rules/prefer-typed-empty-array.js +90 -0
- package/src/rules/require-typed-global.js +60 -0
- package/src/rules/restricted-common.js +211 -0
- package/src/rules/semantic-common.js +105 -0
- package/src/rules/use-isnan.js +28 -0
- package/src/scope.js +1338 -0
- package/src/source-code.js +100 -0
- package/types/ast.d.ts +49 -0
- package/types/index.d.ts +65 -0
- package/types/scope.d.ts +71 -0
- package/wasm/LICENSES/Julia.md +26 -0
- package/wasm/LICENSES/JuliaSyntax-MIT.md +46 -0
- package/wasm/LICENSES/WasmCodegen-MIT.txt +21 -0
- package/wasm/manifest.json +44 -0
- package/wasm/parser.wasm +0 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Generated by scripts/gen-registry.mjs: do not edit the rule lists by hand.
|
|
2
|
+
import { language } from './language.js';
|
|
3
|
+
import { manifest } from './parser/wasm-host.js';
|
|
4
|
+
import noCollapsibleIfRule from './rules/no-collapsible-if.js';
|
|
5
|
+
import noCollectBeforeRangeIterationRule from './rules/no-collect-before-range-iteration.js';
|
|
6
|
+
import noCompareNegativeZeroRule from './rules/no-compare-negative-zero.js';
|
|
7
|
+
import noConcatGrowthInLoopRule from './rules/no-concat-growth-in-loop.js';
|
|
8
|
+
import noCondAssignRule from './rules/no-cond-assign.js';
|
|
9
|
+
import noConstReassignRule from './rules/no-const-reassign.js';
|
|
10
|
+
import noConstantConditionRule from './rules/no-constant-condition.js';
|
|
11
|
+
import noDebuggerRule from './rules/no-debugger.js';
|
|
12
|
+
import noDiscardedCopyResultRule from './rules/no-discarded-copy-result.js';
|
|
13
|
+
import noDupeArgsRule from './rules/no-dupe-args.js';
|
|
14
|
+
import noDupeElseifRule from './rules/no-dupe-elseif.js';
|
|
15
|
+
import noDuplicateDictKeysRule from './rules/no-duplicate-dict-keys.js';
|
|
16
|
+
import noDuplicateKeywordArgumentsRule from './rules/no-duplicate-keyword-arguments.js';
|
|
17
|
+
import noDuplicateLogicalOperandsRule from './rules/no-duplicate-logical-operands.js';
|
|
18
|
+
import noDuplicateMethodSignaturesRule from './rules/no-duplicate-method-signatures.js';
|
|
19
|
+
import noDuplicateStructFieldsRule from './rules/no-duplicate-struct-fields.js';
|
|
20
|
+
import noEmptyBlockRule from './rules/no-empty-block.js';
|
|
21
|
+
import noEmptyCatchRule from './rules/no-empty-catch.js';
|
|
22
|
+
import noEmptyLiteralRangeRule from './rules/no-empty-literal-range.js';
|
|
23
|
+
import noEnvMutationRule from './rules/no-env-mutation.js';
|
|
24
|
+
import noEvalLocalSymbolRule from './rules/no-eval-local-symbol.js';
|
|
25
|
+
import noFillWithMutableRule from './rules/no-fill-with-mutable.js';
|
|
26
|
+
import noFullSliceInConsumerRule from './rules/no-full-slice-in-consumer.js';
|
|
27
|
+
import noIdenticalBranchesRule from './rules/no-identical-branches.js';
|
|
28
|
+
import noImportAssignRule from './rules/no-import-assign.js';
|
|
29
|
+
import noImpossibleLengthComparisonRule from './rules/no-impossible-length-comparison.js';
|
|
30
|
+
import noInvalidForeignCallSignatureRule from './rules/no-invalid-foreign-call-signature.js';
|
|
31
|
+
import noIsdefinedLocalCallRule from './rules/no-isdefined-local-call.js';
|
|
32
|
+
import noLossOfFloatIntegerPrecisionRule from './rules/no-loss-of-float-integer-precision.js';
|
|
33
|
+
import noNothingReturnConversionRule from './rules/no-nothing-return-conversion.js';
|
|
34
|
+
import noObviousTypePiracyRule from './rules/no-obvious-type-piracy.js';
|
|
35
|
+
import noOrphanFileRule from './rules/no-orphan-file.js';
|
|
36
|
+
import noOverwrittenLiteralIndexRule from './rules/no-overwritten-literal-index.js';
|
|
37
|
+
import noReassignedCaptureRule from './rules/no-reassigned-capture.js';
|
|
38
|
+
import noRedundantTypeAssertionRule from './rules/no-redundant-type-assertion.js';
|
|
39
|
+
import noRedundantUnionMembersRule from './rules/no-redundant-union-members.js';
|
|
40
|
+
import noRestrictedCallsRule from './rules/no-restricted-calls.js';
|
|
41
|
+
import noRestrictedImportsRule from './rules/no-restricted-imports.js';
|
|
42
|
+
import noRestrictedMacrosRule from './rules/no-restricted-macros.js';
|
|
43
|
+
import noSelfAssignRule from './rules/no-self-assign.js';
|
|
44
|
+
import noSelfIdentityComparisonRule from './rules/no-self-identity-comparison.js';
|
|
45
|
+
import noShadowedLoopVarRule from './rules/no-shadowed-loop-var.js';
|
|
46
|
+
import noShowMacroRule from './rules/no-show-macro.js';
|
|
47
|
+
import noSingleIterationLoopRule from './rules/no-single-iteration-loop.js';
|
|
48
|
+
import noStringGrowthInLoopRule from './rules/no-string-growth-in-loop.js';
|
|
49
|
+
import noThrowLiteralRule from './rules/no-throw-literal.js';
|
|
50
|
+
import noUnboundTypeParametersRule from './rules/no-unbound-type-parameters.js';
|
|
51
|
+
import noUndefRule from './rules/no-undef.js';
|
|
52
|
+
import noUndefinedExportsRule from './rules/no-undefined-exports.js';
|
|
53
|
+
import noUninitializedRefReadRule from './rules/no-uninitialized-ref-read.js';
|
|
54
|
+
import noUnreachableRule from './rules/no-unreachable.js';
|
|
55
|
+
import noUnsafeFinallyRule from './rules/no-unsafe-finally.js';
|
|
56
|
+
import noUnsafeNegationRule from './rules/no-unsafe-negation.js';
|
|
57
|
+
import noUnusedExpressionsRule from './rules/no-unused-expressions.js';
|
|
58
|
+
import noUnusedTypeParametersRule from './rules/no-unused-type-parameters.js';
|
|
59
|
+
import noUnusedVarsRule from './rules/no-unused-vars.js';
|
|
60
|
+
import noUseBeforeDefineRule from './rules/no-use-before-define.js';
|
|
61
|
+
import noUselessAssignmentRule from './rules/no-useless-assignment.js';
|
|
62
|
+
import noUselessCatchRule from './rules/no-useless-catch.js';
|
|
63
|
+
import parseErrorsRule from './rules/parse-errors.js';
|
|
64
|
+
import preferAnyRule from './rules/prefer-any.js';
|
|
65
|
+
import preferConstGlobalRule from './rules/prefer-const-global.js';
|
|
66
|
+
import preferCountOverFindallLengthRule from './rules/prefer-count-over-findall-length.js';
|
|
67
|
+
import preferEachindexRule from './rules/prefer-eachindex.js';
|
|
68
|
+
import preferExtremeOverSortRule from './rules/prefer-extreme-over-sort.js';
|
|
69
|
+
import preferGeneratorSumRule from './rules/prefer-generator-sum.js';
|
|
70
|
+
import preferIdentityNothingRule from './rules/prefer-identity-nothing.js';
|
|
71
|
+
import preferInRule from './rules/prefer-in.js';
|
|
72
|
+
import preferIsaRule from './rules/prefer-isa.js';
|
|
73
|
+
import preferIsemptyRule from './rules/prefer-isempty.js';
|
|
74
|
+
import preferIsmissingRule from './rules/prefer-ismissing.js';
|
|
75
|
+
import preferParenthesizedInterpolationRule from './rules/prefer-parenthesized-interpolation.js';
|
|
76
|
+
import preferSizeDimensionRule from './rules/prefer-size-dimension.js';
|
|
77
|
+
import preferSizedPushBufferRule from './rules/prefer-sized-push-buffer.js';
|
|
78
|
+
import preferTypedEmptyArrayRule from './rules/prefer-typed-empty-array.js';
|
|
79
|
+
import requireTypedGlobalRule from './rules/require-typed-global.js';
|
|
80
|
+
import useIsnanRule from './rules/use-isnan.js';
|
|
81
|
+
|
|
82
|
+
const plugin = {
|
|
83
|
+
meta: { name: 'eslint-plugin-julia', version: `0.3.0+wasm.${manifest.sha256}` },
|
|
84
|
+
languages: { julia: language },
|
|
85
|
+
rules: {
|
|
86
|
+
'no-collapsible-if': noCollapsibleIfRule,
|
|
87
|
+
'no-collect-before-range-iteration': noCollectBeforeRangeIterationRule,
|
|
88
|
+
'no-compare-negative-zero': noCompareNegativeZeroRule,
|
|
89
|
+
'no-concat-growth-in-loop': noConcatGrowthInLoopRule,
|
|
90
|
+
'no-cond-assign': noCondAssignRule,
|
|
91
|
+
'no-const-reassign': noConstReassignRule,
|
|
92
|
+
'no-constant-condition': noConstantConditionRule,
|
|
93
|
+
'no-debugger': noDebuggerRule,
|
|
94
|
+
'no-discarded-copy-result': noDiscardedCopyResultRule,
|
|
95
|
+
'no-dupe-args': noDupeArgsRule,
|
|
96
|
+
'no-dupe-elseif': noDupeElseifRule,
|
|
97
|
+
'no-duplicate-dict-keys': noDuplicateDictKeysRule,
|
|
98
|
+
'no-duplicate-keyword-arguments': noDuplicateKeywordArgumentsRule,
|
|
99
|
+
'no-duplicate-logical-operands': noDuplicateLogicalOperandsRule,
|
|
100
|
+
'no-duplicate-method-signatures': noDuplicateMethodSignaturesRule,
|
|
101
|
+
'no-duplicate-struct-fields': noDuplicateStructFieldsRule,
|
|
102
|
+
'no-empty-block': noEmptyBlockRule,
|
|
103
|
+
'no-empty-catch': noEmptyCatchRule,
|
|
104
|
+
'no-empty-literal-range': noEmptyLiteralRangeRule,
|
|
105
|
+
'no-env-mutation': noEnvMutationRule,
|
|
106
|
+
'no-eval-local-symbol': noEvalLocalSymbolRule,
|
|
107
|
+
'no-fill-with-mutable': noFillWithMutableRule,
|
|
108
|
+
'no-full-slice-in-consumer': noFullSliceInConsumerRule,
|
|
109
|
+
'no-identical-branches': noIdenticalBranchesRule,
|
|
110
|
+
'no-import-assign': noImportAssignRule,
|
|
111
|
+
'no-impossible-length-comparison': noImpossibleLengthComparisonRule,
|
|
112
|
+
'no-invalid-foreign-call-signature': noInvalidForeignCallSignatureRule,
|
|
113
|
+
'no-isdefined-local-call': noIsdefinedLocalCallRule,
|
|
114
|
+
'no-loss-of-float-integer-precision': noLossOfFloatIntegerPrecisionRule,
|
|
115
|
+
'no-nothing-return-conversion': noNothingReturnConversionRule,
|
|
116
|
+
'no-obvious-type-piracy': noObviousTypePiracyRule,
|
|
117
|
+
'no-orphan-file': noOrphanFileRule,
|
|
118
|
+
'no-overwritten-literal-index': noOverwrittenLiteralIndexRule,
|
|
119
|
+
'no-reassigned-capture': noReassignedCaptureRule,
|
|
120
|
+
'no-redundant-type-assertion': noRedundantTypeAssertionRule,
|
|
121
|
+
'no-redundant-union-members': noRedundantUnionMembersRule,
|
|
122
|
+
'no-restricted-calls': noRestrictedCallsRule,
|
|
123
|
+
'no-restricted-imports': noRestrictedImportsRule,
|
|
124
|
+
'no-restricted-macros': noRestrictedMacrosRule,
|
|
125
|
+
'no-self-assign': noSelfAssignRule,
|
|
126
|
+
'no-self-identity-comparison': noSelfIdentityComparisonRule,
|
|
127
|
+
'no-shadowed-loop-var': noShadowedLoopVarRule,
|
|
128
|
+
'no-show-macro': noShowMacroRule,
|
|
129
|
+
'no-single-iteration-loop': noSingleIterationLoopRule,
|
|
130
|
+
'no-string-growth-in-loop': noStringGrowthInLoopRule,
|
|
131
|
+
'no-throw-literal': noThrowLiteralRule,
|
|
132
|
+
'no-unbound-type-parameters': noUnboundTypeParametersRule,
|
|
133
|
+
'no-undef': noUndefRule,
|
|
134
|
+
'no-undefined-exports': noUndefinedExportsRule,
|
|
135
|
+
'no-uninitialized-ref-read': noUninitializedRefReadRule,
|
|
136
|
+
'no-unreachable': noUnreachableRule,
|
|
137
|
+
'no-unsafe-finally': noUnsafeFinallyRule,
|
|
138
|
+
'no-unsafe-negation': noUnsafeNegationRule,
|
|
139
|
+
'no-unused-expressions': noUnusedExpressionsRule,
|
|
140
|
+
'no-unused-type-parameters': noUnusedTypeParametersRule,
|
|
141
|
+
'no-unused-vars': noUnusedVarsRule,
|
|
142
|
+
'no-use-before-define': noUseBeforeDefineRule,
|
|
143
|
+
'no-useless-assignment': noUselessAssignmentRule,
|
|
144
|
+
'no-useless-catch': noUselessCatchRule,
|
|
145
|
+
'parse-errors': parseErrorsRule,
|
|
146
|
+
'prefer-any': preferAnyRule,
|
|
147
|
+
'prefer-const-global': preferConstGlobalRule,
|
|
148
|
+
'prefer-count-over-findall-length': preferCountOverFindallLengthRule,
|
|
149
|
+
'prefer-eachindex': preferEachindexRule,
|
|
150
|
+
'prefer-extreme-over-sort': preferExtremeOverSortRule,
|
|
151
|
+
'prefer-generator-sum': preferGeneratorSumRule,
|
|
152
|
+
'prefer-identity-nothing': preferIdentityNothingRule,
|
|
153
|
+
'prefer-in': preferInRule,
|
|
154
|
+
'prefer-isa': preferIsaRule,
|
|
155
|
+
'prefer-isempty': preferIsemptyRule,
|
|
156
|
+
'prefer-ismissing': preferIsmissingRule,
|
|
157
|
+
'prefer-parenthesized-interpolation': preferParenthesizedInterpolationRule,
|
|
158
|
+
'prefer-size-dimension': preferSizeDimensionRule,
|
|
159
|
+
'prefer-sized-push-buffer': preferSizedPushBufferRule,
|
|
160
|
+
'prefer-typed-empty-array': preferTypedEmptyArrayRule,
|
|
161
|
+
'require-typed-global': requireTypedGlobalRule,
|
|
162
|
+
'use-isnan': useIsnanRule,
|
|
163
|
+
},
|
|
164
|
+
configs: {},
|
|
165
|
+
};
|
|
166
|
+
// Each rule links to its documentation at the matching release tag.
|
|
167
|
+
for (const [name, rule] of Object.entries(plugin.rules))
|
|
168
|
+
rule.meta.docs = {
|
|
169
|
+
...rule.meta.docs,
|
|
170
|
+
url: `https://github.com/pankgeorg/eslint-plugin-julia/blob/v0.3.0/docs/rules/${name}.md`,
|
|
171
|
+
};
|
|
172
|
+
const config = (rules) => ({
|
|
173
|
+
files: ['**/*.jl'],
|
|
174
|
+
plugins: { julia: plugin },
|
|
175
|
+
language: 'julia/julia',
|
|
176
|
+
rules,
|
|
177
|
+
});
|
|
178
|
+
const RECOMMENDED = {
|
|
179
|
+
'parse-errors': 'error',
|
|
180
|
+
'no-duplicate-struct-fields': 'error',
|
|
181
|
+
'no-duplicate-keyword-arguments': 'error',
|
|
182
|
+
'no-dupe-args': 'error',
|
|
183
|
+
'no-unreachable': 'error',
|
|
184
|
+
'no-unsafe-finally': 'error',
|
|
185
|
+
'no-import-assign': 'error',
|
|
186
|
+
'use-isnan': 'error',
|
|
187
|
+
'prefer-ismissing': 'error',
|
|
188
|
+
'no-isdefined-local-call': 'error',
|
|
189
|
+
'no-invalid-foreign-call-signature': 'error',
|
|
190
|
+
'no-uninitialized-ref-read': 'error',
|
|
191
|
+
'no-shadowed-loop-var': 'warn',
|
|
192
|
+
'no-dupe-elseif': 'warn',
|
|
193
|
+
'no-duplicate-logical-operands': 'warn',
|
|
194
|
+
'no-const-reassign': 'warn',
|
|
195
|
+
'no-self-assign': 'warn',
|
|
196
|
+
'no-unsafe-negation': 'warn',
|
|
197
|
+
'no-unused-expressions': 'warn',
|
|
198
|
+
'no-fill-with-mutable': 'warn',
|
|
199
|
+
'no-discarded-copy-result': 'warn',
|
|
200
|
+
'no-duplicate-dict-keys': 'warn',
|
|
201
|
+
'no-nothing-return-conversion': 'warn',
|
|
202
|
+
'no-debugger': 'warn',
|
|
203
|
+
'no-undef': 'warn',
|
|
204
|
+
'no-orphan-file': 'warn',
|
|
205
|
+
};
|
|
206
|
+
plugin.configs.recommended = config(
|
|
207
|
+
Object.fromEntries(Object.entries(RECOMMENDED).map(([n, level]) => [`julia/${n}`, level])),
|
|
208
|
+
);
|
|
209
|
+
plugin.configs.style = config({
|
|
210
|
+
'julia/prefer-identity-nothing': 'warn',
|
|
211
|
+
'julia/no-empty-catch': 'warn',
|
|
212
|
+
'julia/prefer-parenthesized-interpolation': 'warn',
|
|
213
|
+
});
|
|
214
|
+
// strict: recommended plus every other rule as a warning (style, policy and the scope rules that
|
|
215
|
+
// need a complete environment: no-undef, no-unused-vars, …).
|
|
216
|
+
const STRICT = { 'no-undef': ['warn', { fragments: 'report' }] };
|
|
217
|
+
plugin.configs.strict = config(
|
|
218
|
+
Object.fromEntries(
|
|
219
|
+
Object.keys(plugin.rules).map((n) => [`julia/${n}`, STRICT[n] ?? RECOMMENDED[n] ?? 'warn']),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
plugin.configs.all = config(
|
|
223
|
+
Object.fromEntries(Object.keys(plugin.rules).map((n) => [`julia/${n}`, 'error'])),
|
|
224
|
+
);
|
|
225
|
+
export default plugin;
|
|
226
|
+
export { JuliaSourceCode } from './source-code.js';
|
package/src/language.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseJulia } from './parser/syntax-tree.js';
|
|
2
|
+
import { ParserTrapError } from './parser/wasm-host.js';
|
|
3
|
+
import { JuliaSourceCode } from './source-code.js';
|
|
4
|
+
|
|
5
|
+
export function createJuliaLanguage(parse = parseJulia) {
|
|
6
|
+
return {
|
|
7
|
+
fileType: 'text',
|
|
8
|
+
lineStart: 1,
|
|
9
|
+
columnStart: 0,
|
|
10
|
+
nodeTypeKey: 'type',
|
|
11
|
+
visitorKeys: { JuliaFile: ['children'] },
|
|
12
|
+
defaultLanguageOptions: { recover: false },
|
|
13
|
+
validateLanguageOptions(options) {
|
|
14
|
+
for (const [key, value] of Object.entries(options)) {
|
|
15
|
+
if (key !== 'recover') throw new TypeError(`Unknown Julia language option: ${key}`);
|
|
16
|
+
if (typeof value !== 'boolean')
|
|
17
|
+
throw new TypeError('Julia language option recover must be boolean');
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
parse(file, { languageOptions = {} } = {}) {
|
|
21
|
+
let result;
|
|
22
|
+
try {
|
|
23
|
+
result = parse(file.body);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (!(error instanceof ParserTrapError)) throw error;
|
|
26
|
+
return { ok: false, errors: [{ message: error.message, line: 1, column: 1 }] };
|
|
27
|
+
}
|
|
28
|
+
// ESLint's FileError columns are 1-based (unlike AST loc columns).
|
|
29
|
+
const errors = result.diagnostics
|
|
30
|
+
.filter((d) => d.level === 1)
|
|
31
|
+
.map((d) => ({
|
|
32
|
+
message: d.message,
|
|
33
|
+
line: d.loc.start.line,
|
|
34
|
+
column: d.loc.start.column + 1,
|
|
35
|
+
endLine: d.loc.end.line,
|
|
36
|
+
endColumn: d.loc.end.column + 1,
|
|
37
|
+
}));
|
|
38
|
+
if (errors.length && !languageOptions.recover) return { ok: false, errors };
|
|
39
|
+
return { ok: true, ...result };
|
|
40
|
+
},
|
|
41
|
+
createSourceCode(file, result) {
|
|
42
|
+
return new JuliaSourceCode(file.body, result);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export const language = createJuliaLanguage();
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// Macro signatures: how the scope pass treats a macro call's arguments without expanding it.
|
|
2
|
+
//
|
|
3
|
+
// A signature is `{ args?: Role[], rest?: Role, last?: Role, kw?: Role, scope?, form? }`:
|
|
4
|
+
// `args[i]` is the role of the i-th argument, `last` the role of the final one (when there
|
|
5
|
+
// are more arguments than `args`), `rest` the role of every other argument, and `kw` the
|
|
6
|
+
// role of the right-hand side of a top-level `name = value` argument (its `name` is a
|
|
7
|
+
// symbol). A string is shorthand for `{ rest: role }`. Roles:
|
|
8
|
+
//
|
|
9
|
+
// - `expr`: ordinary code. Every name it reads must be defined; written assignments,
|
|
10
|
+
// loops and functions define names as they would outside the macro.
|
|
11
|
+
// - `bind`: a declaration. Names in head positions (`x`, `x = …`, `x::T`, `x(t)`,
|
|
12
|
+
// `x[1:3]`, operands of a top-level comparison, the same inside a `begin`
|
|
13
|
+
// block) are defined in `scope`; everything else is read.
|
|
14
|
+
// - `maybe`: like `bind`, but a head-position name only becomes a binding when nothing
|
|
15
|
+
// else defines it. The default for macros not in the table.
|
|
16
|
+
// - `quote`: generated code: names are not read here and define nothing, except that
|
|
17
|
+
// `$x` interpolations read `x`. Definitions written in it are kept (`@eval`).
|
|
18
|
+
// - `fields`: `a::T` field lists: `a` is a symbol, `T` is read.
|
|
19
|
+
// - `pattern`: a MacroTools-style pattern: `x_`/`xs__`/`x_T` bind `x`/`xs`; other
|
|
20
|
+
// names are symbols.
|
|
21
|
+
// - `symbol`: a name that is not a variable (`@goto label`).
|
|
22
|
+
// - `skip`: not analyzed.
|
|
23
|
+
// - `decorator`: a definition the macro re-emits at module scope, possibly wrapped in a
|
|
24
|
+
// lambda (Markdown's `@breaking true -> function f(…) … end`).
|
|
25
|
+
//
|
|
26
|
+
// `scope` (for `bind`): `enclosing` (the enclosing function or module, the default) or
|
|
27
|
+
// `global` (the module). `inner` gives the arguments a scope of their own (`@testset`).
|
|
28
|
+
// `form` selects one of the handlers in scope.js for shapes a role list can't express:
|
|
29
|
+
// `kwdef` (field defaults may read earlier fields), `ccall` (the callee is a symbol),
|
|
30
|
+
// `deprecate` (the old signature defines a global, the new one reads only its callee),
|
|
31
|
+
// `inject: [names]` lists names the macro defines around its arguments.
|
|
32
|
+
// `placeholders: true` makes the arguments of a bound call head (`f(t)`) symbols, not reads.
|
|
33
|
+
// `binding: 'assignment'` makes `bind` names ordinary assignments in the current scope
|
|
34
|
+
// (`@gensym x`, Pluto's `@bind x widget`) instead of macro bindings. A `kw` role applies
|
|
35
|
+
// from the second argument on. Forms: `signature` (`@register_symbolic f(x::Real)` defines the global `f`; its
|
|
36
|
+
// arguments are parameter names), `doc` (a documented signature is not code), `eval` (`@eval [module] code`: the code is
|
|
37
|
+
// `quote`d), `plottype` (`@userplot Name` defines `name` and `name!`), `accessor` (`@m a.b body`
|
|
38
|
+
// makes `b` a variable of `body`).
|
|
39
|
+
|
|
40
|
+
const EXPR = { rest: 'expr', kw: 'expr' };
|
|
41
|
+
const CODE = { rest: 'expr' };
|
|
42
|
+
const BIND = { rest: 'bind' };
|
|
43
|
+
|
|
44
|
+
export const ROLES = new Set([
|
|
45
|
+
'expr',
|
|
46
|
+
'bind',
|
|
47
|
+
'maybe',
|
|
48
|
+
'quote',
|
|
49
|
+
'fields',
|
|
50
|
+
'pattern',
|
|
51
|
+
'symbol',
|
|
52
|
+
'skip',
|
|
53
|
+
'decorator',
|
|
54
|
+
]);
|
|
55
|
+
export const UNKNOWN = Object.freeze({ rest: 'maybe' });
|
|
56
|
+
|
|
57
|
+
const table = {
|
|
58
|
+
// Logging, tests and benchmarks: operands are values; `key = value` after the first
|
|
59
|
+
// argument is a keyword (`@info "msg" x=1`, `@test a ≈ b atol=0.1`, `setup=(…)`).
|
|
60
|
+
...Object.fromEntries(
|
|
61
|
+
[
|
|
62
|
+
'@info',
|
|
63
|
+
'@warn',
|
|
64
|
+
'@error',
|
|
65
|
+
'@debug',
|
|
66
|
+
'@logmsg',
|
|
67
|
+
'@test',
|
|
68
|
+
'@test_throws',
|
|
69
|
+
'@test_logs',
|
|
70
|
+
'@test_warn',
|
|
71
|
+
'@test_nowarn',
|
|
72
|
+
'@test_deprecated',
|
|
73
|
+
'@btime',
|
|
74
|
+
'@benchmark',
|
|
75
|
+
'@belapsed',
|
|
76
|
+
'@ballocated',
|
|
77
|
+
].map((m) => [m, EXPR]),
|
|
78
|
+
),
|
|
79
|
+
// Assertions, timing, introspection: operands are ordinary code (`@time x = f()` assigns).
|
|
80
|
+
...Object.fromEntries(
|
|
81
|
+
[
|
|
82
|
+
'@assert',
|
|
83
|
+
'@show',
|
|
84
|
+
'@showtime',
|
|
85
|
+
'@inferred',
|
|
86
|
+
'@time',
|
|
87
|
+
'@timev',
|
|
88
|
+
'@timed',
|
|
89
|
+
'@elapsed',
|
|
90
|
+
'@allocated',
|
|
91
|
+
'@allocations',
|
|
92
|
+
'@printf',
|
|
93
|
+
'@sprintf',
|
|
94
|
+
'@code_warntype',
|
|
95
|
+
'@code_typed',
|
|
96
|
+
'@code_lowered',
|
|
97
|
+
'@code_llvm',
|
|
98
|
+
'@code_native',
|
|
99
|
+
'@which',
|
|
100
|
+
'@edit',
|
|
101
|
+
'@less',
|
|
102
|
+
'@functionloc',
|
|
103
|
+
'@invoke',
|
|
104
|
+
'@invokelatest',
|
|
105
|
+
'@cfunction',
|
|
106
|
+
'@timeit',
|
|
107
|
+
'@profile',
|
|
108
|
+
'@fetch',
|
|
109
|
+
'@fetchfrom',
|
|
110
|
+
'@spawnat',
|
|
111
|
+
'@something',
|
|
112
|
+
'@lock',
|
|
113
|
+
'@lock_nofail',
|
|
114
|
+
'@preserve',
|
|
115
|
+
].map((m) => [m, CODE]),
|
|
116
|
+
),
|
|
117
|
+
// Pass-through: the argument is ordinary code.
|
|
118
|
+
...Object.fromEntries(
|
|
119
|
+
[
|
|
120
|
+
'@inbounds',
|
|
121
|
+
'@boundscheck',
|
|
122
|
+
'@views',
|
|
123
|
+
'@view',
|
|
124
|
+
'@inline',
|
|
125
|
+
'@noinline',
|
|
126
|
+
'@propagate_inbounds',
|
|
127
|
+
'@simd',
|
|
128
|
+
'@threads',
|
|
129
|
+
'@spawn',
|
|
130
|
+
'@async',
|
|
131
|
+
'@sync',
|
|
132
|
+
'@static',
|
|
133
|
+
'@fastmath',
|
|
134
|
+
'@__dot__',
|
|
135
|
+
'@atomic',
|
|
136
|
+
'@atomicswap',
|
|
137
|
+
'@atomicreplace',
|
|
138
|
+
'@atomiconce',
|
|
139
|
+
'@nospecialize',
|
|
140
|
+
'@specialize',
|
|
141
|
+
'@generated',
|
|
142
|
+
'@assume_effects',
|
|
143
|
+
'@constprop',
|
|
144
|
+
'@noinfer',
|
|
145
|
+
'@nospecializeinfer',
|
|
146
|
+
'@task',
|
|
147
|
+
'@distributed',
|
|
148
|
+
'@everywhere',
|
|
149
|
+
'@reexport',
|
|
150
|
+
'@compat',
|
|
151
|
+
'@pure',
|
|
152
|
+
'@series',
|
|
153
|
+
'@muladd',
|
|
154
|
+
'@pack!',
|
|
155
|
+
'@__doc__',
|
|
156
|
+
].map((m) => [m, CODE]),
|
|
157
|
+
),
|
|
158
|
+
'@testset': { ...EXPR, scope: 'inner' },
|
|
159
|
+
'@eval': { form: 'eval' },
|
|
160
|
+
'@goto': { rest: 'symbol' },
|
|
161
|
+
'@label': { rest: 'symbol' },
|
|
162
|
+
'@NamedTuple': { rest: 'fields' },
|
|
163
|
+
'@Kwargs': { rest: 'fields' },
|
|
164
|
+
'@enum': { rest: 'bind', scope: 'global' },
|
|
165
|
+
'@cenum': { rest: 'bind', scope: 'global' },
|
|
166
|
+
'@gensym': { rest: 'bind', binding: 'assignment' },
|
|
167
|
+
'@bind': { args: ['bind', 'expr'], scope: 'global', binding: 'assignment' },
|
|
168
|
+
'@deprecate_binding': { args: ['bind', 'expr'], scope: 'global' },
|
|
169
|
+
'@deprecate': { form: 'deprecate' },
|
|
170
|
+
'@doc': { form: 'doc' },
|
|
171
|
+
'@kwdef': { form: 'kwdef' },
|
|
172
|
+
'@with_kw': { form: 'kwdef' },
|
|
173
|
+
'@with_kw_noshow': { form: 'kwdef' },
|
|
174
|
+
'@ccall': { form: 'ccall' },
|
|
175
|
+
// A method signature, not code (ChainRulesCore, Symbolics).
|
|
176
|
+
'@non_differentiable': { form: 'doc' },
|
|
177
|
+
'@scalar_rule': { rest: 'skip' },
|
|
178
|
+
'@register_symbolic': { form: 'signature' },
|
|
179
|
+
'@register_array_symbolic': { form: 'signature' },
|
|
180
|
+
'@register_derivative': { rest: 'skip' },
|
|
181
|
+
// Destructuring and symbolic declarations.
|
|
182
|
+
'@unpack': BIND,
|
|
183
|
+
'@variables': BIND,
|
|
184
|
+
'@parameters': BIND,
|
|
185
|
+
'@constants': BIND,
|
|
186
|
+
// `@syms f(t)`: `t` names an argument of the symbolic function, it isn't read.
|
|
187
|
+
'@syms': { rest: 'bind', placeholders: true },
|
|
188
|
+
'@brownian': BIND,
|
|
189
|
+
'@independent_variables': BIND,
|
|
190
|
+
'@named': BIND,
|
|
191
|
+
'@mtkbuild': BIND,
|
|
192
|
+
'@mtkcompile': BIND,
|
|
193
|
+
'@capture': { args: ['expr', 'pattern'] },
|
|
194
|
+
// RecipesBase: a recipe's body reads the `plotattributes` it is given.
|
|
195
|
+
'@recipe': { rest: 'expr', inject: ['plotattributes'] },
|
|
196
|
+
// Index notation (TensorOperations, Tullio, Einsum, TensorCast): indices are bound by
|
|
197
|
+
// the macro.
|
|
198
|
+
'@tensor': { rest: 'skip' },
|
|
199
|
+
'@tensoropt': { rest: 'skip' },
|
|
200
|
+
'@tullio': { rest: 'skip' },
|
|
201
|
+
'@einsum': { rest: 'skip' },
|
|
202
|
+
'@cast': { rest: 'skip' },
|
|
203
|
+
'@reduce': { rest: 'skip' },
|
|
204
|
+
'@matmul': { rest: 'skip' },
|
|
205
|
+
// Markdown's parser registration: the function is defined at module scope.
|
|
206
|
+
'@breaking': { rest: 'decorator' },
|
|
207
|
+
'@trigger': { rest: 'decorator' },
|
|
208
|
+
// Base.Cartesian generates `i_1`, `i_2`, … from its arguments.
|
|
209
|
+
...Object.fromEntries(
|
|
210
|
+
[
|
|
211
|
+
'@nloops',
|
|
212
|
+
'@nref',
|
|
213
|
+
'@ncall',
|
|
214
|
+
'@ncallkw',
|
|
215
|
+
'@nexprs',
|
|
216
|
+
'@ntuple',
|
|
217
|
+
'@nall',
|
|
218
|
+
'@nany',
|
|
219
|
+
'@nif',
|
|
220
|
+
'@nextract',
|
|
221
|
+
].map((m) => [m, { rest: 'skip' }]),
|
|
222
|
+
),
|
|
223
|
+
};
|
|
224
|
+
// `@isdefined x` asks whether `x` exists: it never reads it.
|
|
225
|
+
table['@isdefined'] = { rest: 'skip' };
|
|
226
|
+
// Code that is expanded, skipped or expected to fail, not run as written.
|
|
227
|
+
for (const m of ['@macroexpand', '@macroexpand1', '@test_skip', '@test_broken'])
|
|
228
|
+
table[m] = { rest: 'skip' };
|
|
229
|
+
// SymbolicUtils' operator generator: `a`, `b` and `f` in its templates are placeholders.
|
|
230
|
+
table['@number_methods'] = { args: ['expr'], rest: 'skip' };
|
|
231
|
+
// Moshi: `@derive T[Show, Eq]` names traits; `@data T begin Variant(Fields) … end` declares
|
|
232
|
+
// a type and its variants. EnumX: `@enumx T begin a; b end` declares T (values are `T.a`).
|
|
233
|
+
table['@derive'] = { rest: 'skip' };
|
|
234
|
+
table['@data'] = { rest: 'bind', scope: 'global' };
|
|
235
|
+
table['@enumx'] = { args: ['bind'], rest: 'skip', scope: 'global' };
|
|
236
|
+
// JET's test harness: code to analyze, not code to run.
|
|
237
|
+
table['@analyze_toplevel'] = { rest: 'skip' };
|
|
238
|
+
// Symbolics' `@num_method f (… a … b …) Domain`: the same placeholders.
|
|
239
|
+
table['@num_method'] = { args: ['expr', 'skip'], rest: 'expr' };
|
|
240
|
+
// Plot types (Makie's `@recipe Name (args) begin … end`, RecipesBase's `@userplot`,
|
|
241
|
+
// `@shorthands`) define their plotting functions; see scope.js.
|
|
242
|
+
table['@userplot'] = { form: 'plottype' };
|
|
243
|
+
table['@shorthands'] = { form: 'plottype' };
|
|
244
|
+
// WGLMakie's event handlers: `@handle msg.mousedown begin … end` binds `mousedown`.
|
|
245
|
+
table['@handle'] = { form: 'accessor' };
|
|
246
|
+
|
|
247
|
+
const normalize = (spec) => (typeof spec === 'string' ? { rest: spec } : spec);
|
|
248
|
+
const cache = new WeakMap();
|
|
249
|
+
|
|
250
|
+
/** The signature of `name` (`@info`), with user signatures (`settings.julia.macros`) first. */
|
|
251
|
+
export function macroSignature(name, user) {
|
|
252
|
+
if (user && typeof user === 'object') {
|
|
253
|
+
let merged = cache.get(user);
|
|
254
|
+
if (!merged) {
|
|
255
|
+
merged = new Map();
|
|
256
|
+
for (const [k, v] of Object.entries(user)) {
|
|
257
|
+
const spec = normalize(v);
|
|
258
|
+
if (spec && typeof spec === 'object') merged.set(k.startsWith('@') ? k : `@${k}`, spec);
|
|
259
|
+
}
|
|
260
|
+
cache.set(user, merged);
|
|
261
|
+
}
|
|
262
|
+
if (merged.has(name)) return merged.get(name);
|
|
263
|
+
}
|
|
264
|
+
return Object.hasOwn(table, name) ? table[name] : UNKNOWN;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The role of argument `index` of `count` under `spec`. */
|
|
268
|
+
export function roleOf(spec, index, count) {
|
|
269
|
+
const role =
|
|
270
|
+
spec.args?.[index] ??
|
|
271
|
+
(spec.last && index === count - 1 && index >= (spec.args?.length ?? 0) ? spec.last : null) ??
|
|
272
|
+
spec.rest ??
|
|
273
|
+
'expr';
|
|
274
|
+
return ROLES.has(role) ? role : 'expr';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export const builtinMacroSignatures = table;
|