Skip to content

Commit

Permalink
feat: add "eslint/universal" to export Linter (#18883)
Browse files Browse the repository at this point in the history
* feat: add "eslint/universal" to export `Linter`

fixes #18715

* fix: add lib/universal.js

* feat: add typings

* chore: add tests for "eslint/universal" types

* Update lib/types/universal.d.ts

Co-authored-by: Francesco Trotta <github@fasttime.org>

* chore: update types tests

---------

Co-authored-by: Francesco Trotta <github@fasttime.org>
  • Loading branch information
aladdin-add and fasttime authored Sep 18, 2024
1 parent c591da6 commit ec30c73
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module.exports = [
{
name: "eslint/lib",
files: ["lib/*.js"],
ignores: ["lib/unsupported-api.js"],
ignores: ["lib/unsupported-api.js", "lib/universal.js"],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns()
Expand Down
6 changes: 6 additions & 0 deletions lib/types/universal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @fileoverview typings for "eslint/universal" module
* @author 唯然<weiran.zsd@outlook.com>
*/

export { Linter } from "./index";
10 changes: 10 additions & 0 deletions lib/universal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @fileoverview exports for browsers
* @author 唯然<weiran.zsd@outlook.com>
*/

"use strict";

const { Linter } = require("./linter/linter");

module.exports = { Linter };
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
},
"./rules": {
"types": "./lib/types/rules/index.d.ts"
},
"./universal": {
"types": "./lib/types/universal.d.ts",
"default": "./lib/universal.js"
}
},
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import { AST, ESLint, Linter, loadESLint, Rule, RuleTester, Scope, SourceCode } from "eslint";
import { ESLintRules } from "eslint/rules";
import { Linter as ESLinter } from "eslint/universal";
import {
builtinRules,
FileEnumerator,
Expand Down Expand Up @@ -579,6 +580,7 @@ rule = {
// #region Linter

const linter = new Linter();
const eslinter = new ESLinter();

linter.version;

Expand Down
21 changes: 21 additions & 0 deletions tests/lib/universal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @fileoverview Tests for "eslint/universal".
* @author 唯然<weiran.zsd@outlook.com>
*/

"use strict";
const assert = require("node:assert/strict");

describe("universal", () => {
it("should have Linter exported", () => {
const { Linter } = require("eslint/universal");

assert.ok(Linter);
assert.ok(typeof Linter === "function");


const linter = new Linter();

assert.ok(linter);
});
});

0 comments on commit ec30c73

Please sign in to comment.