Skip to content

Commit f9b6882

Browse files
Adds rule that detects potential sensitive tokens in ts, js and json files (#1)
1 parent c19c6a2 commit f9b6882

15 files changed

+2652
-1
lines changed

.github/workflows/basic.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Basic Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
nodeVersion: 22
11+
12+
jobs:
13+
prepare:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install npm dependencies
18+
run: npm install
19+
20+
lint:
21+
runs-on: ubuntu-latest
22+
needs: prepare
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- run: npm install
27+
- run: npm run lint
28+
29+
test:
30+
runs-on: ubuntu-latest
31+
needs: prepare
32+
steps:
33+
- uses: actions/checkout@v4
34+
- run: npm install
35+
- run: npm run test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.nvm

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

.prettierrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
singleQuote: true
2+
trailingComma: 'none'
3+
arrowParens: 'always'

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## 1.0.0 (2025-03-13)
4+
- Add custom rule for detecting potential sensitive tokens in js, ts and json files

README.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
11
# eslint-plugin-mapbox-token
2-
Eslint plugin that recognizes tokens in js, ts and json files
2+
3+
This eslint plugin contains custom eslint rules.
4+
5+
## Usage
6+
7+
```sh
8+
npm install --save-dev @mapbox/eslint-plugin-mapbox
9+
```
10+
11+
12+
Example of eslint.config.cjs for eslint version 9:
13+
14+
```sh
15+
const mapbox = require('@mapbox/eslint-plugin-mapbox');
16+
module.exports = [
17+
...mapbox.configs.recommended,
18+
]
19+
```
20+
21+
22+
Example of eslint config file for eslint version 8:
23+
24+
```sh
25+
module.exports = {
26+
extends: 'eslint:recommended',
27+
env: {
28+
es6: true
29+
},
30+
parserOptions: {
31+
ecmaVersion: 2020
32+
},
33+
plugins: ['jsonc', '@mapbox/mapbox'],
34+
rules: {
35+
... other rules
36+
'@mapbox/mapbox/detect-token': 'error'
37+
},
38+
overrides: [
39+
{
40+
files: ['*.json', '*.jsonc'],
41+
parser: 'jsonc-eslint-parser',
42+
rules: {
43+
44+
... other rules
45+
'@mapbox/mapbox/detect-token'': 'error',
46+
}
47+
}
48+
]
49+
};
50+
```
51+
52+
## Rules
53+
54+
`detect-token` : Detects potential sensitive tokens in .ts, .tsx, .js, .jsx and .json files

eslint.config.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
4+
export default [
5+
js.configs.recommended,
6+
{
7+
languageOptions: {
8+
globals: {
9+
...globals.node
10+
}
11+
}
12+
}
13+
];

index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const detectTokenRule = require('./rules/detect-token');
4+
5+
const plugin = {
6+
rules: {
7+
'detect-token': detectTokenRule
8+
},
9+
configs: {}
10+
};
11+
12+
Object.assign(plugin.configs, {
13+
recommended: [
14+
{
15+
plugins: {
16+
'@mapbox/mapbox': plugin
17+
},
18+
rules: {
19+
'@mapbox/mapbox/detect-token': 'error'
20+
}
21+
}
22+
]
23+
});
24+
25+
module.exports = plugin;

0 commit comments

Comments
 (0)