Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
egdelgadillo committed Jan 14, 2023
0 parents commit 1dfdb90
Show file tree
Hide file tree
Showing 19 changed files with 11,756 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-check
'use strict';

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
root: true,
extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended', 'plugin:node/recommended'],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
env: {
node: true,
},
overrides: [
{
files: ['tests/**/*.js'],
env: { mocha: true },
},
],
plugins: ['require-ts-check'],
rules: {
'require-ts-check/require-ts-check': 'error',
},
};
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
push:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'pnpm'

- run: pnpm install --frozen-lockfile
- run: pnpm run lint && pnpm run test
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish
on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'pnpm'
registry-url: https://registry.npmjs.org

- run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
tabWidth: 2,
printWidth: 120,
singleQuote: true,
trailingComma: 'es5',
};
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["EditorConfig.EditorConfig", "dbaeumer.vscode-eslint", "rvest.vs-code-prettier-eslint"]
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
"editor.formatOnPaste": false,
"editor.formatOnType": false,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"[javascript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[json]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[md]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
}
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# eslint-plugin-require-ts-check

## v0.0.1

Initial release

### Patch changes

- By default this plugin will include `.js` files and ignore the `node_modules` folder.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# eslint-plugin-require-ts-check

Require @ts-check to be added in your javascript files

## Table of contents

- [Table of contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Supported Parameters](#supported-parameters)
- [Contributing](#contributing)

## Installation

You'll first need to install [ESLint](https://eslint.org/):

```sh
npm i eslint --save-dev
```

Next, install `eslint-plugin-require-ts-check`:

```sh
npm install eslint-plugin-require-ts-check --save-dev
```

## Usage

Add `eslint-plugin-require-ts-check` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": ["require-ts-check"]
}
```

Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"require-ts-check/require-ts-check": "error"
}
}
```

## Supported options

This rule supports a combination of any of the following options:

### include

Specify the files that should be tested using this rule. This parameter uses the [Glob filename matching pattern](<https://en.wikipedia.org/wiki/Glob_(programming)>).

Defaults to all javascript files: `[ "**/*.js" ]`

#### `include` Usage

```json
"rules": {
"require-ts-check/require-ts-check": ["error", { "include": ["**/my-files/*.*"] }]
}
```

### exclude

Specify the files that this rule should ignore. This parameter uses the [Glob filename matching pattern](<https://en.wikipedia.org/wiki/Glob_(programming)>).

Defaults to the `node_modules` folder: `[ "node_modules" ]`

#### `exclude` Usage

```json
"rules": {
"require-ts-check/require-ts-check": ["error", { "exclude": ["**/ignored-files/*.*"] }]
}
```

## Contributing

1. Install VSCode recommended extensions. This is needed for formatting.

In Mac: <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>:

Others: <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>:

Find "Extensions: Show recommended extensions" and install them

Always format the code when saving

2. Create a new changelog entry by running `pnpm changeset` and fill in the data
3. Run tests `pnpm test`
4. Run prettier `pnpm prettier`
5. Run lint `pnpm lint`
6. Push your changes and create a PR for your branch pointing to `main`.
122 changes: 122 additions & 0 deletions docs/rules/require-ts-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# `require-ts-check`

## Table of contents

- [Options](#options)
- [Examples](#examples)
- [When Not To Use It](#when-not-to-use-it)

Javascript files don't come with type checking enabled by default. In order to enable type checking to a javascript file
we need to add the following single line comment to the top of the file:

```js
// @ts-check
```

In order for this to enable type checking in the file, it needs to be added as a **single line comment** (`// ...`) (`/** */` JSDoc type
comments don't work) and it needs to be added before any code declaration/statement (`import ...`, `const ...`, etc)

This rule enforces that type checking is enabled on the file. Only `.js` files are evaluated.

## Options

This rule accepts some pattern matching options

### `include`

An array of [glob pattern](<https://en.wikipedia.org/wiki/Glob_(programming)>) strings. This will be the files in which the rule will be active.
Partial glob path matching is enabled.

Defaults to `['**/*.js']`

### `exclude`

An array of [glob pattern](<https://en.wikipedia.org/wiki/Glob_(programming)>) strings. This will be the files in which the rule will **not** be active
This option takes precedence before the `include` one, meaning that if a file is matched by both patters, it will be ignored.
Partial glob path matching is enabled.

Defaults to `['node_modules']`

## Examples

### ✅ Correct

The following examples are considered as valid:

```js
// @ts-check
const foo = bar();

...

// @ts-check this doesn't matter
const foo = bar();

...

// A comment
/** Another comment */
// @ts-check
// Final comment
function foo() {
console.log('bar');
};

...

//@ts-check
import foo from 'bar';

...

// @Ts-ChEcK
let foo;

```

### ❌ Incorrect

The following examples are considered as invalid

```js
const foo = bar();
// @ts-check <-- ERROR: Cannot be _below_ any code declaration


...

'use strict';
// @ts-check <- ERROR: Cannot be below expression statements
const foo = bar();

...

// invalid @ts-check <- ERROR: Cannot have any preceding characters
function foo() {
console.log('bar');
};

...

/** @ts-check */ // <- ERROR: Cannot use JSDoc comments
import foo from 'bar';
```

### Pattern matching options

```js
// Include only .js files from the entities folder
'js-type-checking/require-ts-check': ['error', { include: ['**/entities/*.js'] }],

// Exclude all paths matching 'models'
'js-type-checking/require-ts-check': ['error', { exclude: ['models', 'node_modules'] }],

// `exclude` takes precedence over `include`. All .js files will be included except for index.js
'js-type-checking/require-ts-check': ['error', { include: ['**/*.js'], exclude: ['index.js'] }],
```

For more examples, check the tests.

## When Not To Use It

If you don't like enabling type checking on Javascript files.
19 changes: 19 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check
/**
* @fileoverview Require @ts-check to be added to your files
* @author Emiliano Delgadillo
*/
'use strict';

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const requireIndex = require('requireindex');

//------------------------------------------------------------------------------
// Plugin Definition
//------------------------------------------------------------------------------

// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + '/rules');
Loading

0 comments on commit 1dfdb90

Please sign in to comment.