Skip to content

Commit

Permalink
docs(README): add per rule docs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Dec 21, 2021
1 parent 2bdd084 commit 0f7f1a2
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .eslintdocgenrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
docPath: "docs/rules/{name}.md",
rulePath: "src/rules/{name}.ts",
testPath: "src/rules/{name}.test.ts",
// fixCodeExamples doesn't work with ESLint 8.0.0 https://github.com/wikimedia/eslint-docgen/issues/126
fixCodeExamples: false,
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
dist/
.npmrc
**/docs

# Logs
logs
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ accept your pull requests.

3. Run the tests:

# Run tests.
npm test

4. Lint (and maybe fix) any changes:
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ To use rules provided by the plugin, use the following:

## Rules

* `googlemaps/no-api-keys`: [recommended] Disallow Google Maps Platform API keys in source code.
| Rule | Description | Configurations | Type |
| ------------------------------------------ | -------------------------- | ---------------- | ------------ |
| [no-api-keys](docs/rules/no-api-keys.md) | Keep API keys out of code. | ![recommended][] | ![suggest][] |
| [place-fields](docs/rules/place-fields.md) | Always use place fields. | ![recommended][] | ![suggest][] |

[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
[fixable]: https://img.shields.io/badge/-fixable-green.svg
[style]: https://img.shields.io/badge/-style-blue.svg
32 changes: 32 additions & 0 deletions docs/rules/no-api-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.)

# no-api-keys

Avoid placing API keys in source code. Instead use build tools that insert the API key using environment variables similar to:

```js
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
```

This pattern enables use of development keys and prevents use of production keys that may have higher quotas.

📋 This rule is enabled in `plugin:googlemaps/recommended`.

## Rule details

❌ Examples of **incorrect** code:
```js
const apiKey = "AIza00000000000000000000000000000000000";
```

✔️ Examples of **correct** code:
```js
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
const apiKey = "YOUR_API_KEY";
const apiKey = "AIzaSomeStringThatDoesntMatch";
```

## Resources

* [Rule source](/src/rules/no-api-keys.ts)
* [Test source](/src/rules/no-api-keys.test.ts)
53 changes: 53 additions & 0 deletions docs/rules/place-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.)

# place-fields

Use the `fields` option to limit the fields returned by the API and costs. Request to the Places API are billed by the fields that are returned. See [data-skus](https://developers.google.com/maps/documentation/places/web-service/usage-and-billing#data-skus) for more details.
> **Note**: This rule is not exhaustive and ignores `Autocomplete.setFields()`.
📋 This rule is enabled in `plugin:googlemaps/recommended`.

## Rule details

❌ Examples of **incorrect** code:
```js
const service = new google.maps.places.PlacesService();
const request = {place_id: 'foo'};
service.getDetails(request)

const service = new google.maps.places.PlacesService();
service.getDetails({})

const service = new google.maps.places.PlacesService();
service.getDetails({...{bar: 'foo'}})

const service = new google.maps.places.Autocomplete(null, {});
const service = new google.maps.places.Autocomplete(null);
```

✔️ Examples of **correct** code:
```js
const service = new google.maps.places.PlacesService();
const request = {place_id: 'foo', fields: ['place_id']};
service.getDetails(request)

const service = new google.maps.places.PlacesService();
service.getDetails({place_id: 'foo', fields: ['place_id']})

const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo', fields: ['place_id']}})

const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo', 'fields': ['place_id']}})

const service = new google.maps.places.PlacesService();
const buildRequest = () => {};
service.getDetails(buildRequest())

const service = new google.maps.places.Autocomplete(null, {fields: ['place_id']});
```

## Resources

* [Rule source](/src/rules/place-fields.ts)
* [Test source](/src/rules/place-fields.test.ts)
8 changes: 5 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
"^.+\\.tsx?$": "ts-jest",
},
collectCoverage: true,
testPathIgnorePatterns: ['/dist/'],
modulePathIgnorePatterns: ['<rootDir>/dist/'],
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.test.ts"],
testPathIgnorePatterns: ["/dist/", "/node_modules/"],
modulePathIgnorePatterns: ["<rootDir>/dist/"],
silent: false,
};
Loading

0 comments on commit 0f7f1a2

Please sign in to comment.