Skip to content

Commit

Permalink
[js] optimize eslint config (#18460)
Browse files Browse the repository at this point in the history
### Description
optimize eslint config to:
- set parserOptions.project to `true` to allow @typescript-eslint/parser
to find the nearest tsconfig.json file to that source file. This helps
to avoid parsing extra files, may helps with:
- reduce the possibility of seeing OOM or stackoverflow with "npm run
lint"
   - faster processing
- enforce rule "no-underscore-dangle" with a list of exceptions.
  • Loading branch information
fs-eire authored Nov 20, 2023
1 parent 1dd9bf5 commit 247ce21
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 18 deletions.
70 changes: 60 additions & 10 deletions js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@

module.exports = {
root: true,
ignorePatterns: ['**/*.js', 'ort-schema/', 'common/test/type-tests/', 'test/data/', 'node_modules/', 'dist/'],
ignorePatterns: [
'**/*.js',
'node_modules/',
'ort-schema/',
'common/test/type-tests/',
'web/types.d.ts',
'test/data/',
'dist/',
],
env: { 'es6': true },
parser: '@typescript-eslint/parser',
parserOptions: { 'project': 'tsconfig.json', 'sourceType': 'module' },
parserOptions: { 'project': true, 'sourceType': 'module' },
plugins: ['@typescript-eslint', 'prefer-arrow', 'header', 'import', 'unicorn', 'jsdoc'],
rules: {
'unicorn/filename-case': 'error',
Expand Down Expand Up @@ -144,15 +152,56 @@ module.exports = {
'no-unused-expressions': 'off',
}
}, {
files: ['web/lib/**/*.ts'],
excludedFiles: 'web/lib/wasm/proxy-worker/**/*',
parserOptions: { 'project': 'web/tsconfig.json' },
rules: {
'no-underscore-dangle': 'off',
files: ['web/lib/**/*.ts'], rules: {
'no-underscore-dangle': ['error', {
'allow': [
'_free',
'_malloc',
'_JsepGetNodeName',
'_JsepOutput',
'_OrtAddFreeDimensionOverride',
'_OrtAddRunConfigEntry',
'_OrtAddSessionConfigEntry',
'_OrtAppendExecutionProvider',
'_OrtBindInput',
'_OrtBindOutput',
'_OrtClearBoundOutputs',
'_OrtCreateBinding',
'_OrtCreateRunOptions',
'_OrtCreateSession',
'_OrtCreateSessionOptions',
'_OrtCreateTensor',
'_OrtEndProfiling',
'_OrtFree',
'_OrtGetInputName',
'_OrtGetInputOutputCount',
'_OrtGetLastError',
'_OrtGetOutputName',
'_OrtGetTensorData',
'_OrtInit',
'_OrtReleaseBinding',
'_OrtReleaseRunOptions',
'_OrtReleaseSession',
'_OrtReleaseSessionOptions',
'_OrtReleaseTensor',
'_OrtRun',
'_OrtRunWithBinding',
'_OrtTrainingCopyParametersFromBuffer',
'_OrtTrainingCopyParametersToBuffer',
'_OrtTrainingCreateSession',
'_OrtTrainingEvalStep',
'_OrtTrainingGetModelInputOutputCount',
'_OrtTrainingGetModelInputOutputName',
'_OrtTrainingGetParametersSize',
'_OrtTrainingLazyResetGrad',
'_OrtTrainingLoadCheckpoint',
'_OrtTrainingOptimizerStep',
'_OrtTrainingReleaseCheckpoint',
'_OrtTrainingReleaseSession',
'_OrtTrainingRunTrainStep'
]
}]
}
}, {
files: ['web/lib/wasm/proxy-worker/**/*.ts'],
parserOptions: { 'project': 'web/lib/wasm/proxy-worker/tsconfig.json' },
}, {
files: ['web/lib/onnxjs/**/*.ts'], rules: {
// TODO: those rules are useful. should turn on them in future (webgl refactor)
Expand All @@ -164,6 +213,7 @@ module.exports = {
'import/no-internal-modules': 'off',
'prefer-arrow/prefer-arrow-functions': 'off',
'no-param-reassign': 'off',
'no-underscore-dangle': 'off',
'guard-for-in': 'off'
}
}, {
Expand Down
8 changes: 4 additions & 4 deletions js/web/lib/onnxjs/attribute-with-cache-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class AttributeWithCacheKeyImpl {
Object.assign(this, attribute);
}

private _cacheKey: string;
private key: string;
public get cacheKey(): string {
if (!this._cacheKey) {
this._cacheKey =
if (!this.key) {
this.key =
Object.getOwnPropertyNames(this).sort().map(name => `${(this as Record<string, unknown>)[name]}`).join(';');
}
return this._cacheKey;
return this.key;
}
}

Expand Down
8 changes: 4 additions & 4 deletions js/web/lib/wasm/jsep/webgpu/attribute-with-cache-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class AttributeWithCacheKeyImpl {
Object.assign(this, attribute);
}

private _cacheKey: string;
private key: string;
public get cacheKey(): string {
if (!this._cacheKey) {
this._cacheKey =
if (!this.key) {
this.key =
Object.getOwnPropertyNames(this).sort().map(name => `${(this as Record<string, unknown>)[name]}`).join(';');
}
return this._cacheKey;
return this.key;
}
}

Expand Down

0 comments on commit 247ce21

Please sign in to comment.