@alextheman/eslint-plugin 1.0.0
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/.github/workflows/ci.yml +36 -0
- package/.github/workflows/npm-publish.yml +27 -0
- package/.husky/pre-commit +3 -0
- package/__tests__/no-namespace-imports.test.ts +24 -0
- package/eslint.config.js +3 -0
- package/jest.config.js +12 -0
- package/package.json +39 -0
- package/src/createRule.ts +7 -0
- package/src/index.ts +14 -0
- package/src/rules/index.ts +5 -0
- package/src/rules/no-namespace-imports.ts +33 -0
- package/tsconfig.json +27 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "main" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "main" ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
ci:
|
|
14
|
+
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [22.x]
|
|
20
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
- name: Setup package
|
|
30
|
+
run: |
|
|
31
|
+
npm ci
|
|
32
|
+
npm run build --if-present
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: npm test
|
|
35
|
+
- name: Run linting checks
|
|
36
|
+
run: npm run lint
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish-npm:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: 20
|
|
19
|
+
registry-url: https://registry.npmjs.org/
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: npm ci
|
|
22
|
+
- name: Build package
|
|
23
|
+
run: npm run build
|
|
24
|
+
- name: Publish to npm
|
|
25
|
+
run: npm publish --access public
|
|
26
|
+
env:
|
|
27
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
2
|
+
import rules from "src/rules";
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
languageOptions: { ecmaVersion: "latest" },
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
ruleTester.run("no-namespace-imports", rules["no-namespace-imports"], {
|
|
9
|
+
valid: [
|
|
10
|
+
{
|
|
11
|
+
code: 'import { useState } from "react"',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
invalid: [
|
|
15
|
+
{
|
|
16
|
+
code: 'import * as React from "react"',
|
|
17
|
+
errors: [
|
|
18
|
+
{
|
|
19
|
+
messageId: "message",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
package/eslint.config.js
ADDED
package/jest.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createDefaultPreset } from "ts-jest";
|
|
2
|
+
|
|
3
|
+
const tsJestTransformCfg = createDefaultPreset().transform;
|
|
4
|
+
|
|
5
|
+
/** @type {import("jest").Config} **/
|
|
6
|
+
export default {
|
|
7
|
+
testEnvironment: "node",
|
|
8
|
+
transform: {
|
|
9
|
+
...tsJestTransformCfg,
|
|
10
|
+
},
|
|
11
|
+
moduleDirectories: ["node_modules", "."]
|
|
12
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alextheman/eslint-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"format": "prettier --write --parser typescript 'src/**/*.ts' '__tests__/**/*.ts' && ESLINT_MODE=fix eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
|
|
9
|
+
"lint": "ESLINT_MODE=lint eslint 'src/**/*.ts' '__tests__/**/*.ts' && prettier --check --parser typescript 'src/**/*.ts' '__tests__/**/*.ts'",
|
|
10
|
+
"update-dependencies": "npx npm-check-updates -u && npm install",
|
|
11
|
+
"prepare": "husky",
|
|
12
|
+
"build": "tsup"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
20
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
21
|
+
"eslint": "^9.31.0",
|
|
22
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
23
|
+
"eslint-plugin-import": "^2.32.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@alextheman/eslint-config-typescript-base": "^1.0.7",
|
|
27
|
+
"@types/eslint": "^9.6.1",
|
|
28
|
+
"@types/jest": "^30.0.0",
|
|
29
|
+
"@typescript-eslint/rule-tester": "^8.36.0",
|
|
30
|
+
"@typescript-eslint/utils": "^8.36.0",
|
|
31
|
+
"eslint": "^9.31.0",
|
|
32
|
+
"eslint-plugin-eslint-plugin": "^6.5.0",
|
|
33
|
+
"husky": "^9.1.7",
|
|
34
|
+
"jest": "^30.0.4",
|
|
35
|
+
"ts-jest": "^29.4.0",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"typescript": "^5.8.3"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import createRule from "src/createRule";
|
|
2
|
+
|
|
3
|
+
const noNamespaceImports = createRule({
|
|
4
|
+
name: "no-namespace-imports",
|
|
5
|
+
meta: {
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Forbid the use of import *",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
message: "Import * is not allowed. Please use named imports instead.",
|
|
11
|
+
},
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
defaultOptions: [],
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
ImportDeclaration(node) {
|
|
19
|
+
if (node.specifiers[0].type === "ImportNamespaceSpecifier") {
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: "message",
|
|
23
|
+
data: {
|
|
24
|
+
source: node.source,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export default noNamespaceImports;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2024"],
|
|
6
|
+
"types": ["eslint"],
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"baseUrl": ".",
|
|
10
|
+
"paths": {
|
|
11
|
+
"src/*": ["src/*"]
|
|
12
|
+
},
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
|
|
20
|
+
"strict": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
"declaration": true
|
|
25
|
+
},
|
|
26
|
+
"include": ["src", "__tests__"]
|
|
27
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
import packageInfo from "./package.json"
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
entry: ["src/index.ts"],
|
|
6
|
+
format: ["esm", "cjs"],
|
|
7
|
+
dts: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
external: [
|
|
10
|
+
...Object.keys(packageInfo.peerDependencies)
|
|
11
|
+
]
|
|
12
|
+
});
|