-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract eslint get souce code to util (#772)
* chore: extract eslint get souce code to util * extract null checks * change import order for better style
- Loading branch information
1 parent
ec13602
commit 93fd979
Showing
4 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { SourceCode } from 'eslint/eslint-rule'; | ||
/*:: import { Rule } from 'eslint'; */ | ||
|
||
// Fallback to legacy `getSourceCode()` for compatibility with older ESLint versions | ||
export default function getSourceCode(context: Rule.RuleContext): SourceCode { | ||
const sourceCode = | ||
context.sourceCode || | ||
(typeof context.getSourceCode === 'function' | ||
? context.getSourceCode() | ||
: null); | ||
if (!sourceCode) { | ||
throw new Error( | ||
'ESLint context does not provide source code access. Please update ESLint to v>=8.40.0. See: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/', | ||
); | ||
} | ||
return sourceCode; | ||
} |