standard-tsx 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [18.x]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Use Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v1
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+ - run: npm install
25
+ - run: npm test
@@ -0,0 +1,22 @@
1
+ name: Repo Commands
2
+
3
+ on:
4
+ issue_comment: # Handle comment commands
5
+ types: [created]
6
+ pull_request: # Handle renamed PRs
7
+ types: [edited]
8
+
9
+ jobs:
10
+ comment-trigger:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Check out repository
14
+ uses: actions/checkout@v3
15
+ - name: Run command handlers
16
+ uses: PrismarineJS/prismarine-repo-actions@master
17
+ with:
18
+ # NOTE: You must specify a Personal Access Token (PAT) with repo access here. While you can use the default GITHUB_TOKEN, actions taken with it will not trigger other actions, so if you have a CI workflow, commits created by this action will not trigger it.
19
+ token: ${{ secrets.GITHUB_TOKEN }}
20
+ # See `Options` section below for more info on these options
21
+ install-command: npm install
22
+ /fixlint.fix-command: npm run fix
@@ -0,0 +1,32 @@
1
+ name: npm-publish
2
+ on:
3
+ push:
4
+ branches:
5
+ - main # Change this to your default branch
6
+ jobs:
7
+ npm-publish:
8
+ name: npm-publish
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout repository
12
+ uses: actions/checkout@master
13
+ - name: Set up Node.js
14
+ uses: actions/setup-node@master
15
+ with:
16
+ node-version: 18.0.0
17
+ - id: publish
18
+ uses: JS-DevTools/npm-publish@v1
19
+ with:
20
+ token: ${{ secrets.NPM_AUTH_TOKEN }}
21
+ - name: Create Release
22
+ if: steps.publish.outputs.type != 'none'
23
+ id: create_release
24
+ uses: actions/create-release@v1
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+ with:
28
+ tag_name: ${{ steps.publish.outputs.version }}
29
+ release_name: Release ${{ steps.publish.outputs.version }}
30
+ body: ${{ steps.publish.outputs.version }}
31
+ draft: false
32
+ prerelease: false
package/.gitpod ADDED
@@ -0,0 +1,2 @@
1
+ tasks:
2
+ - command: npm install
package/HISTORY.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ * Initial release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 extremeheat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # standard-tsx
2
+ [![NPM version](https://img.shields.io/npm/v/standard-tsx.svg)](http://npmjs.com/package/standard-tsx)
3
+ [![Build Status](https://github.com/extremeheat/standard-tsx/actions/workflows/ci.yml/badge.svg)](https://github.com/extremeheat/standard-tsx/actions/workflows/)
4
+ [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/extremeheat/standard-tsx)
5
+
6
+ A drop-in replacement for the `standard` JavaScript linter that supports both TypeScript and JavaScript code with and without JSX. This package does not
7
+ add any new rules. Instead, it applies standard's eslint config (https://github.com/standard/eslint-config-standard) to both `*.ts` and `*.js`/`.cjs`/`.mjs` files as well as `.tsx`/`.jsx` React files. This is on top of ESLint's default TypeScript reccomendations (which are mostly non-style related):
8
+
9
+ >Recommended rules for code correctness that you can drop in without additional configuration. These rules are those whose reports are almost always for a bad practice and/or likely bug. recommended also disables core ESLint rules known to conflict with typescript-eslint rules or cause issues in TypeScript codebases.
10
+
11
+ ## Install
12
+ ```
13
+ npm install standard-tsx
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ To run against the current directory (analogus to `npx eslint .`):
19
+
20
+ ```
21
+ npx standard-tsx
22
+ ```
23
+
24
+ Or to fix
25
+ ```
26
+ npx standard-tsx --fix
27
+ ```
28
+
29
+ In package.json run scripts, you can add the following as aliases (which will run in context of your repo root):
30
+ ```json
31
+ "scripts": {
32
+ "lint": "standard-tsx",
33
+ "fix": "standard-tsx --fix"
34
+ },
35
+ ```
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "standard-tsx",
3
+ "version": "0.0.1",
4
+ "description": "standardjs lint with typescript file support (with no new typescript rules)",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "standard-tsx": "./src/cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "mocha --reporter spec --exit",
11
+ "pretest": "npm run lint",
12
+ "lint": "standard-tsx",
13
+ "fix": "standard-tsx --fix"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/extremeheat/standard-tsx.git"
18
+ },
19
+ "keywords": [],
20
+ "author": "extremeheat",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/extremeheat/standard-tsx/issues"
24
+ },
25
+ "homepage": "https://github.com/extremeheat/standard-tsx#readme",
26
+ "devDependencies": {
27
+ "mocha": "^10.0.0",
28
+ "standard-tsx": "file:."
29
+ },
30
+ "dependencies": {
31
+ "@eslint/js": "^9.21.0",
32
+ "@typescript-eslint/eslint-plugin": "^8.26.0",
33
+ "@typescript-eslint/parser": "^8.26.0",
34
+ "eslint": "^9.21.0",
35
+ "eslint-config-standard": "^17.1.0",
36
+ "eslint-plugin-eslint-env-restore": "^1.0.0",
37
+ "eslint-plugin-react": "^7.37.4",
38
+ "eslint-plugin-react-hooks": "^5.2.0",
39
+ "globals": "^16.0.0",
40
+ "typescript-eslint": "^8.26.0"
41
+ },
42
+ "__comment": "We need overrides as `eslint-config-standard` depends on eslint@8 and we only need config",
43
+ "overrides": {
44
+ "eslint": "^9.21.0"
45
+ }
46
+ }
package/src/cli.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ // bin/my-eslint.js
3
+
4
+ const { ESLint } = require('eslint')
5
+ const path = require('path')
6
+ const fs = require('fs')
7
+
8
+ async function main () {
9
+ const args = process.argv.slice(2)
10
+ const fixFlag = args.includes('--fix')
11
+ // Remove the --fix flag from args if present
12
+ const patterns = args.filter(arg => arg !== '--fix')
13
+
14
+ // Default to current directory if no patterns provided
15
+ if (patterns.length === 0) {
16
+ patterns.push('.')
17
+ }
18
+
19
+ // Check for custom rules in the project's package.json
20
+ let customRules = {}
21
+ try {
22
+ const projectPackageJson = path.join(process.cwd(), 'package.json')
23
+ if (fs.existsSync(projectPackageJson)) {
24
+ const pkg = require(projectPackageJson)
25
+ if (pkg.eslintRules) {
26
+ customRules = pkg.eslintRules
27
+ }
28
+ }
29
+ } catch (error) {
30
+ console.warn('Failed to load custom rules from package.json')
31
+ }
32
+
33
+ // Initialize ESLint with our config
34
+ const eslint = new ESLint({
35
+ overrideConfigFile: path.join(__dirname, './eslint.config.js'),
36
+ fix: fixFlag,
37
+ overrideConfig: {
38
+ rules: customRules
39
+ }
40
+ })
41
+
42
+ try {
43
+ // Lint files
44
+ const results = await eslint.lintFiles(patterns)
45
+
46
+ // Apply fixes if --fix was specified
47
+ if (fixFlag) {
48
+ await ESLint.outputFixes(results)
49
+ }
50
+
51
+ // Format and output results
52
+ const formatter = await eslint.loadFormatter('stylish')
53
+ const resultText = formatter.format(results)
54
+ console.log(resultText)
55
+
56
+ // Determine exit code based on results
57
+ const errorCount = results.reduce((count, result) => count + result.errorCount, 0)
58
+ process.exitCode = errorCount > 0 ? 1 : 0
59
+ } catch (error) {
60
+ console.error('Error running ESLint:', error)
61
+ process.exitCode = 1
62
+ }
63
+ }
64
+
65
+ main()
@@ -0,0 +1,41 @@
1
+ // ./env-restore.js
2
+ const envGlobals = require('globals')
3
+
4
+ function extractEslintEnv (text) {
5
+ const firstLine = text.split('\n')[0].trim()
6
+ if (firstLine.startsWith('/* eslint-env ') && firstLine.endsWith('*/')) {
7
+ const envPart = firstLine.slice(14, -2).trim()
8
+ return envPart.split(',').map(env => env.trim())
9
+ }
10
+ return []
11
+ }
12
+
13
+ function mapEnvsToGlobals (envs) {
14
+ const globals = {}
15
+ envs.forEach(env => {
16
+ if (envGlobals[env]) {
17
+ Object.assign(globals, envGlobals[env])
18
+ }
19
+ })
20
+ return globals
21
+ }
22
+
23
+ module.exports = {
24
+ processors: {
25
+ js: {
26
+ preprocess (text, filename) {
27
+ const envs = extractEslintEnv(text)
28
+ if (envs.length === 0) return [text]
29
+
30
+ const globals = mapEnvsToGlobals(envs)
31
+ const globalNames = Object.keys(globals).join(', ')
32
+ const injectedComment = `/* global ${globalNames} */ ${text}`
33
+ return [injectedComment]
34
+ },
35
+ postprocess (messages) {
36
+ return messages[0]
37
+ },
38
+ supportsAutofix: true
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,143 @@
1
+ // ./eslint.config.js
2
+ const globals = require('globals')
3
+ const pluginJs = require('@eslint/js').configs
4
+ const tseslint = require('typescript-eslint')
5
+ const standard = require('eslint-config-standard')
6
+ const importPlugin = require('eslint-plugin-import')
7
+ const nPlugin = require('eslint-plugin-n')
8
+ const promisePlugin = require('eslint-plugin-promise')
9
+ const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore')
10
+ const reactPlugin = require('eslint-plugin-react') // Added React plugin
11
+ const reactHooksPlugin = require('eslint-plugin-react-hooks') // Added React Hooks plugin
12
+
13
+ module.exports = [
14
+ {
15
+ languageOptions: {
16
+ globals: {
17
+ ...standard.globals,
18
+ ...globals.es2021
19
+ }
20
+ }
21
+ },
22
+ // JavaScript (Node.js environment)
23
+ {
24
+ files: ['**/*.{js,cjs,mjs}'],
25
+ languageOptions: {
26
+ globals: {
27
+ ...globals.node,
28
+ require: 'readonly',
29
+ module: 'writable',
30
+ exports: 'writable'
31
+ }
32
+ },
33
+ plugins: {
34
+ 'eslint-env-restore': eslintEnvRestorePlugin,
35
+ import: importPlugin,
36
+ n: nPlugin,
37
+ promise: promisePlugin
38
+ },
39
+ processor: 'eslint-env-restore/js',
40
+ rules: {
41
+ ...pluginJs.recommended.rules,
42
+ ...standard.rules,
43
+ 'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }]
44
+ }
45
+ },
46
+ // JSX (Browser environment)
47
+ {
48
+ files: ['**/*.jsx'],
49
+ languageOptions: {
50
+ globals: {
51
+ ...globals.browser
52
+ },
53
+ parserOptions: {
54
+ ecmaFeatures: {
55
+ jsx: true
56
+ }
57
+ }
58
+ },
59
+ plugins: {
60
+ 'eslint-env-restore': eslintEnvRestorePlugin,
61
+ import: importPlugin,
62
+ n: nPlugin,
63
+ promise: promisePlugin,
64
+ react: reactPlugin, // Added React plugin
65
+ 'react-hooks': reactHooksPlugin // Added React Hooks plugin
66
+ },
67
+ processor: 'eslint-env-restore/js',
68
+ rules: {
69
+ ...pluginJs.recommended.rules,
70
+ ...standard.rules,
71
+ ...reactPlugin.configs.recommended.rules, // React recommended rules
72
+ ...reactHooksPlugin.configs.recommended.rules, // React Hooks recommended rules
73
+ 'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
74
+ 'react/jsx-uses-react': 'off', // Disabled for React 17+
75
+ 'react/jsx-uses-vars': 'error',
76
+ 'react/react-in-jsx-scope': 'off' // Disabled for React 17+
77
+ }
78
+ },
79
+ // TypeScript (Node.js environment)
80
+ {
81
+ files: ['**/*.ts'],
82
+ languageOptions: {
83
+ parser: tseslint.parser,
84
+ parserOptions: {
85
+ project: './tsconfig.json'
86
+ },
87
+ globals: {
88
+ ...globals.node
89
+ }
90
+ },
91
+ plugins: {
92
+ 'eslint-env-restore': eslintEnvRestorePlugin,
93
+ '@typescript-eslint': tseslint.plugin,
94
+ import: importPlugin,
95
+ n: nPlugin,
96
+ promise: promisePlugin
97
+ },
98
+ processor: 'eslint-env-restore/js',
99
+ rules: {
100
+ ...tseslint.configs.recommended.rules,
101
+ ...standard.rules,
102
+ 'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
103
+ '@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }]
104
+ }
105
+ },
106
+ // TSX (Browser environment)
107
+ {
108
+ files: ['**/*.tsx'],
109
+ languageOptions: {
110
+ parser: tseslint.parser,
111
+ parserOptions: {
112
+ project: './tsconfig.json',
113
+ ecmaFeatures: {
114
+ jsx: true
115
+ }
116
+ },
117
+ globals: {
118
+ ...globals.browser
119
+ }
120
+ },
121
+ plugins: {
122
+ 'eslint-env-restore': eslintEnvRestorePlugin,
123
+ '@typescript-eslint': tseslint.plugin,
124
+ import: importPlugin,
125
+ n: nPlugin,
126
+ promise: promisePlugin,
127
+ react: reactPlugin, // Added React plugin
128
+ 'react-hooks': reactHooksPlugin // Added React Hooks plugin
129
+ },
130
+ processor: 'eslint-env-restore/js',
131
+ rules: {
132
+ ...tseslint.configs.recommended.rules,
133
+ ...standard.rules,
134
+ ...reactPlugin.configs.recommended.rules, // React recommended rules
135
+ ...reactHooksPlugin.configs.recommended.rules, // React Hooks recommended rules
136
+ 'no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
137
+ '@typescript-eslint/no-unused-vars': ['error', { vars: 'local', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true }],
138
+ 'react/jsx-uses-react': 'off', // Disabled for React 17+
139
+ 'react/jsx-uses-vars': 'error',
140
+ 'react/react-in-jsx-scope': 'off' // Disabled for React 17+
141
+ }
142
+ }
143
+ ]
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ config: require('./eslint.config.js')
3
+ }
@@ -0,0 +1,8 @@
1
+ /* eslint-env mocha */
2
+
3
+ describe('basic', () => {
4
+ it('test', () => {
5
+ require('standard-tsx')
6
+ console.log('it works~')
7
+ })
8
+ })