-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3d40a0
commit 2fc8bc6
Showing
10 changed files
with
122 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import js from "@eslint/js"; | ||
import { ignores } from "./lib/index.js"; | ||
|
||
export default [js.configs.recommended, ignores()]; |
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,18 @@ | ||
/** | ||
* @param {object} [opts] | ||
* @param {string?} [opts.cwd] | ||
* @param {string?} [opts.filename] | ||
* @param {string[]?} [opts.extraIgnores] | ||
* @returns {{ignores: string[]}} the list of ignored files | ||
*/ | ||
export function ignores( | ||
opts?: | ||
| { | ||
cwd?: string | null | undefined; | ||
filename?: string | null | undefined; | ||
extraIgnores?: string[] | null | undefined; | ||
} | ||
| undefined | ||
): { | ||
ignores: string[]; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,30 @@ | ||
"use strict"; | ||
/** | ||
* @fileoverview eslint ignore files automatically. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
import process from "process"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export function add(a, b) { | ||
return a + b; | ||
/** | ||
* @param {object} [opts] | ||
* @param {string} [opts.cwd] | ||
* @param {string} [opts.filename] | ||
* @param {string[]?} [opts.extraIgnores] | ||
* @returns {{ignores: string[]}} the list of ignored files | ||
*/ | ||
export function ignores(opts = {}) { | ||
const ignoreFile = path.join( | ||
opts.cwd || process.cwd(), | ||
opts.filename || ".gitignore" | ||
); | ||
const text = fs.readFileSync(ignoreFile, "utf-8"); | ||
const lines = text | ||
.split(/(\r\n|\n)+/) | ||
.map((line) => line.trim()) | ||
.filter((line) => line && !line.startsWith("#")); | ||
|
||
return { | ||
ignores: [...lines, ...(opts.extraIgnores || [])], | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,52 +1,48 @@ | ||
{ | ||
"name": "@weiran.zsd/js-starter", | ||
"name": "@weiran.zsd/eslint-ignores", | ||
"version": "0.0.0", | ||
"private": false, | ||
"description": "A full featured node.js starter.", | ||
"description": "eslint ignore files automatically.", | ||
"keywords": [ | ||
"Node.js", | ||
"template", | ||
"eslint", | ||
"eslint-plugin", | ||
"gitignore", | ||
"esm" | ||
], | ||
"license": "MIT", | ||
"author": "唯然<[email protected]", | ||
"type": "module", | ||
"exports": "./lib/index.js", | ||
"typings": "./lib/index.d.ts", | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"lib", | ||
"!**/*.test.{js,ts}" | ||
], | ||
"scripts": { | ||
"lint": "eslint lib", | ||
"lint": "eslint .", | ||
"prepare": "husky install", | ||
"prettier": "prettier -w lib", | ||
"prettier": "prettier -w ./*.js ./lib/*.js", | ||
"release": "npm test && standard-version", | ||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", | ||
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:node/recommended" | ||
] | ||
"test:typings": "tsc", | ||
"test:unit": "node tests/index.spec.js" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^8.45.0", | ||
"@tsconfig/node-lts": "^18.12.3", | ||
"@tsconfig/node20": "^20.1.0", | ||
"@tsconfig/recommended": "^1.0.2", | ||
"@types/node": "^20.4.4", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.3.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint": "^8.45.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.4.3", | ||
"lint-staged": "^12.1.2", | ||
"prettier": "^2.3.2", | ||
"standard-version": "^9.3.0" | ||
"standard-version": "^9.3.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=16" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,31 +1,28 @@ | ||
# Node.js starter | ||
# eslint-ignores | ||
|
||
## Usage | ||
|
||
```sh | ||
$ npx degit weiran.zsd/starter | ||
$ npm install @weiran.zsd/eslint-ignores -D | ||
``` | ||
|
||
```sh | ||
# run linting | ||
$ npm run lint [-- --fix] | ||
```js | ||
// eslint.config.js | ||
import js from "@eslint/js"; | ||
import { ignores } from "@weiran.zsd/eslint-ignores"; | ||
|
||
# run test | ||
$ npm test | ||
export default [js.configs.recommended, ignores()]; | ||
``` | ||
|
||
# watching test | ||
$ npm run test:watch | ||
## Options | ||
|
||
# release | ||
$ npm run release | ||
``` | ||
TODO - add options | ||
|
||
|
||
## Credits | ||
|
||
* [aladdin-add](https://github.com/aladdin-add) | ||
|
||
## Features | ||
## License | ||
|
||
* Node.js esm | ||
* prettier | ||
* eslint + eslint-plugin-node | ||
* pre-commit with husky | ||
* release with standard-version | ||
* testing with jest | ||
* gh actions | ||
MIT. |
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,13 @@ | ||
import test from "node:test"; | ||
import { strict as t } from "node:assert/strict"; | ||
import { ignores } from "../lib/index.js"; | ||
|
||
test("ignores", function () { | ||
t(typeof ignores === "function"); | ||
|
||
const config = ignores(); | ||
|
||
t(config); | ||
t(Array.isArray(config.ignores)); | ||
t(config.ignores.includes("/node_modules")); | ||
}); |
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,10 @@ | ||
{ | ||
"extends": "@tsconfig/node20/tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"declaration": true, | ||
"noEmit": true | ||
}, | ||
"include": ["lib/", "tests/index.spec.js"] | ||
} |