Skip to content

Commit

Permalink
feat: ignores first impl
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 31, 2023
1 parent e3d40a0 commit 2fc8bc6
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 69 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: "16.x"
- name: Install dependencies
run: npm install
- name: Lint files
Expand All @@ -29,17 +29,17 @@ jobs:
os: [ubuntu-latest]
node: [17.x, 16.x, 14.x, 12.x, "12.22.0"]
include:
- os: windows-latest
node: "16.x"
- os: macOS-latest
node: "16.x"
- os: windows-latest
node: "16.x"
- os: macOS-latest
node: "16.x"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018 薛定谔的猫
Copyright (c) 唯然

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.js
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()];
18 changes: 18 additions & 0 deletions lib/index.d.ts
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[];
};
31 changes: 28 additions & 3 deletions lib/index.js
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 || [])],
};
}
10 changes: 0 additions & 10 deletions lib/index.test.js

This file was deleted.

40 changes: 18 additions & 22 deletions package.json
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"
}
}
37 changes: 17 additions & 20 deletions readme.md
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.
13 changes: 13 additions & 0 deletions tests/index.spec.js
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"));
});
10 changes: 10 additions & 0 deletions tsconfig.json
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"]
}

0 comments on commit 2fc8bc6

Please sign in to comment.