Skip to content

Commit

Permalink
[Refactor] create sourceType helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 30, 2024
1 parent 0bc1355 commit 1fa8a07
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/core/sourceType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {import('eslint').Rule.RuleContext} context
* @returns 'module' | 'script' | undefined
*/
export default function sourceType(context) {
return context.parserOptions.sourceType;
}
3 changes: 2 additions & 1 deletion src/rules/no-default-export.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getSourceCode } from 'eslint-module-utils/contextCompat';

import docsUrl from '../docsUrl';
import sourceType from '../core/sourceType';

module.exports = {
meta: {
Expand All @@ -15,7 +16,7 @@ module.exports = {

create(context) {
// ignore non-modules
if (context.parserOptions.sourceType !== 'module') {
if (sourceType(context) !== 'module') {
return {};
}

Expand Down
3 changes: 2 additions & 1 deletion src/rules/no-named-export.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sourceType from '../core/sourceType';
import docsUrl from '../docsUrl';

module.exports = {
Expand All @@ -13,7 +14,7 @@ module.exports = {

create(context) {
// ignore non-modules
if (context.parserOptions.sourceType !== 'module') {
if (sourceType(context) !== 'module') {
return {};
}

Expand Down
3 changes: 2 additions & 1 deletion src/rules/unambiguous.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { isModule } from 'eslint-module-utils/unambiguous';
import docsUrl from '../docsUrl';
import sourceType from '../core/sourceType';

module.exports = {
meta: {
Expand All @@ -19,7 +20,7 @@ module.exports = {

create(context) {
// ignore non-modules
if (context.parserOptions.sourceType !== 'module') {
if (sourceType(context) !== 'module') {
return {};
}

Expand Down

0 comments on commit 1fa8a07

Please sign in to comment.