Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade parser and add jsonc/no-numeric-separators rule. #22

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 70 additions & 53 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,102 @@
"use strict"

// const version = require("./package.json").version

module.exports = {
parserOptions: {
sourceType: "script",
// sourceType: "script",
ecmaVersion: 2020,
project: require.resolve("./tsconfig.json"),
},
extends: [
"plugin:@mysticatea/es2015",
"plugin:@mysticatea/+node",
"plugin:@mysticatea/+eslint-plugin",
"plugin:@ota-meshi/recommended",
"plugin:@ota-meshi/+node",
"plugin:@ota-meshi/+typescript",
"plugin:@ota-meshi/+eslint-plugin",
"plugin:@ota-meshi/+vue2",
"plugin:@ota-meshi/+prettier",
// "plugin:@ota-meshi/+json",
],
rules: {
"require-jsdoc": "error",
"no-warning-comments": "warn",
"no-lonely-if": "off",
"@mysticatea/ts/ban-ts-ignore": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-shadow": "off",
},
overrides: [
{
files: ["*.ts"],
rules: {
// "@mysticatea/ts/no-require-imports": "off",
// "@mysticatea/ts/no-var-requires": "off",
"@mysticatea/node/no-missing-import": "off",
"no-implicit-globals": "off",
"@mysticatea/node/no-extraneous-import": "off",
"@typescript-eslint/naming-convention": [
"error",
{
selector: "default",
format: ["camelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "typeLike",
format: ["PascalCase"],
},
{
selector: "method",
format: ["camelCase", "UPPER_CASE", "PascalCase"],
},
],
},
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
project: "./tsconfig.json",
},
},
{
files: ["lib/rules/**"],
rules: {
"@mysticatea/eslint-plugin/report-message-format": [
"error",
"[^a-z].*\\.$",
],
"@mysticatea/eslint-plugin/require-meta-docs-url": "off",
},
},
// {
// files: ["lib/rules/**"],
// rules: {
// "eslint-plugin/report-message-format": [
// "error",
// "[^a-z].*\\.$",
// ],
// "eslint-plugin/require-meta-docs-url": "off",
// },
// },
{
files: ["scripts/**/*.ts", "tests/**/*.ts"],
rules: {
"require-jsdoc": "off",
"no-console": "off",
"@typescript-eslint/ban-ts-comment": "off",
},
},
{
files: ["*.vue"],
parserOptions: {
sourceType: "module",
},
globals: {
require: true,
},
},
{
files: ["docs/.vuepress/**"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
parser: "babel-eslint",
},
globals: {
window: true,
},
rules: {
"require-jsdoc": "off",
"@mysticatea/vue/html-closing-bracket-newline": "off",
"@mysticatea/vue/max-attributes-per-line": "off",
"@mysticatea/vue/comma-dangle": "off",
"@mysticatea/vue/html-indent": "off",
"@mysticatea/vue/html-self-closing": "off",
"@mysticatea/node/no-unsupported-features/es-syntax": "off",
"@mysticatea/node/no-missing-import": "off",
"@mysticatea/node/no-missing-require": "off",
},
},
// {
// files: ["*.vue"],
// parserOptions: {
// sourceType: "module",
// },
// globals: {
// require: true,
// },
// },
// {
// files: ["docs/.vuepress/**"],
// parserOptions: {
// sourceType: "module",
// ecmaVersion: 2020,
// parser: "babel-eslint",
// },
// globals: {
// window: true,
// },
// rules: {
// "require-jsdoc": "off",
// },
// },
],
}
4 changes: 2 additions & 2 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
node-version: 14
- name: Install Packages
run: npm install
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Lint
run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ The rules with the following star :star: are included in the config.
| [jsonc/no-bigint-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-bigint-literals.html) | disallow BigInt literals | | :star: | :star: | :star: |
| [jsonc/no-comments](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-comments.html) | disallow comments | | :star: | | |
| [jsonc/no-number-props](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-number-props.html) | disallow number property keys | :wrench: | :star: | :star: | :star: |
| [jsonc/no-numeric-separators](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-numeric-separators.html) | disallow numeric separators | :wrench: | :star: | :star: | :star: |
| [jsonc/no-regexp-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-regexp-literals.html) | disallow RegExp literals | | :star: | :star: | :star: |
| [jsonc/no-template-literals](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-template-literals.html) | disallow template literals | :wrench: | :star: | :star: | :star: |
| [jsonc/no-undefined-value](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-undefined-value.html) | disallow `undefined` | | :star: | :star: | :star: |
Expand Down
8 changes: 8 additions & 0 deletions docs/.vuepress/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 'use strict'

module.exports = {
rules: {
"prettier/prettier": "off",
"require-jsdoc": "off"
},
}
4 changes: 2 additions & 2 deletions docs/.vuepress/components/components/EslintPluginEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
parser: "jsonc-eslint-parser",
parserOptions: {
sourceType: "script",
ecmaVersion: 2020,
ecmaVersion: 2021,
},
}
},
Expand Down Expand Up @@ -121,7 +121,7 @@ export default {
// Load linter asynchronously.
const [{ default: eslint4b }, { parseForESLint }] = await Promise.all([
import("eslint4b"),
// eslint-disable-next-line @mysticatea/node/no-extraneous-import
// eslint-disable-next-line node/no-extraneous-import -- DEMO
import("espree").then(() => import("jsonc-eslint-parser")),
])
this.eslint4b = eslint4b
Expand Down
5 changes: 0 additions & 5 deletions docs/.vuepress/components/demo/.eslintrc.js

This file was deleted.

9 changes: 7 additions & 2 deletions docs/.vuepress/components/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
import * as coreRules from "../../../../node_modules/eslint4b/dist/core-rules"
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
import plugin from "../../../../"

const CATEGORY_TITLES = {
Expand Down Expand Up @@ -51,9 +53,10 @@ for (const k of Object.keys(coreRules)) {
}

allRules.sort((a, b) =>
a.ruleId > b.ruleId ? 1 : a.ruleId < b.ruleId ? -1 : 0
a.ruleId > b.ruleId ? 1 : a.ruleId < b.ruleId ? -1 : 0,
)

// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export const categories = []

for (const rule of allRules) {
Expand All @@ -80,9 +83,10 @@ categories.sort((a, b) =>
? 1
: a.title < b.title
? -1
: 0
: 0,
)

// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export const DEFAULT_RULES_CONFIG = allRules.reduce((c, r) => {
if (r.ruleId === "vue/no-parsing-error") {
c[r.ruleId] = "error"
Expand All @@ -92,4 +96,5 @@ export const DEFAULT_RULES_CONFIG = allRules.reduce((c, r) => {
return c
}, {})

// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export const rules = allRules
2 changes: 2 additions & 0 deletions docs/.vuepress/components/state/deserialize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
import pako from "../../../../node_modules/pako"

/**
* Deserialize a given serialized string then update this object.
* @param {string} serializedString A serialized string.
* @returns {object} The deserialized state.
*/
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export function deserializeState(serializedString) {
const state = {
code: undefined,
Expand Down
2 changes: 2 additions & 0 deletions docs/.vuepress/components/state/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export * from "./deserialize"
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export * from "./serialize"
5 changes: 3 additions & 2 deletions docs/.vuepress/components/state/serialize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
import pako from "../../../../node_modules/pako"

/**
Expand All @@ -19,6 +20,7 @@ function getEnabledRules(allRules) {
* @param {State} state The state to serialize.
* @returns {string} The serialized string.
*/
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export function serializeState(state) {
const saveData = {
code: state.code,
Expand All @@ -30,12 +32,11 @@ export function serializeState(state) {
(typeof window !== "undefined" && window.btoa(compressedString)) ||
compressedString

//eslint-disable-next-line no-console
console.log(
`The compress rate of serialized string: ${(
(100 * base64.length) /
jsonString.length
).toFixed(1)}% (${jsonString.length}B → ${base64.length}B)`
).toFixed(1)}% (${jsonString.length}B → ${base64.length}B)`,
)

return base64
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/enhanceApp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line node/no-unsupported-features/es-syntax -- DEMO
export default () =>
// {
// Vue, // the version of Vue being used in the VuePress app
Expand Down
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The rules with the following star :star: are included in the `plugin:jsonc/recom
| [jsonc/no-bigint-literals](./no-bigint-literals.md) | disallow BigInt literals | | :star: | :star: | :star: |
| [jsonc/no-comments](./no-comments.md) | disallow comments | | :star: | | |
| [jsonc/no-number-props](./no-number-props.md) | disallow number property keys | :wrench: | :star: | :star: | :star: |
| [jsonc/no-numeric-separators](./no-numeric-separators.md) | disallow numeric separators | :wrench: | :star: | :star: | :star: |
| [jsonc/no-regexp-literals](./no-regexp-literals.md) | disallow RegExp literals | | :star: | :star: | :star: |
| [jsonc/no-template-literals](./no-template-literals.md) | disallow template literals | :wrench: | :star: | :star: | :star: |
| [jsonc/no-undefined-value](./no-undefined-value.md) | disallow `undefined` | | :star: | :star: | :star: |
Expand Down
41 changes: 41 additions & 0 deletions docs/rules/no-numeric-separators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
pageClass: "rule-details"
sidebarDepth: 0
title: "jsonc/no-numeric-separators"
description: "disallow numeric separators"
---
# jsonc/no-numeric-separators

> disallow numeric separators

- :gear: This rule is included in all of `"plugin:jsonc/recommended-with-json"`, `"plugin:jsonc/recommended-with-json5"` and `"plugin:jsonc/recommended-with-jsonc"`.
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

## :book: Rule Details

This rule reports the use of numeric separators.


<eslint-code-block fix>

```json5
/* eslint jsonc/no-numeric-separators: 'error' */
{
/* ✓ GOOD */
"GOOD": 1234567890,

/* ✗ BAD */
"BAD": 1_234_567_890
}
```

</eslint-code-block>

## :wrench: Options

Nothing.

## Implementation

- [Rule source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/rules/no-numeric-separators.ts)
- [Test source](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/tests/lib/rules/no-numeric-separators.js)
1 change: 1 addition & 0 deletions lib/configs/recommended-with-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export = {
"jsonc/no-dupe-keys": "error",
"jsonc/no-multi-str": "error",
"jsonc/no-number-props": "error",
"jsonc/no-numeric-separators": "error",
"jsonc/no-regexp-literals": "error",
"jsonc/no-sparse-arrays": "error",
"jsonc/no-template-literals": "error",
Expand Down
1 change: 1 addition & 0 deletions lib/configs/recommended-with-json5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export = {
"jsonc/no-bigint-literals": "error",
"jsonc/no-dupe-keys": "error",
"jsonc/no-number-props": "error",
"jsonc/no-numeric-separators": "error",
"jsonc/no-regexp-literals": "error",
"jsonc/no-sparse-arrays": "error",
"jsonc/no-template-literals": "error",
Expand Down
1 change: 1 addition & 0 deletions lib/configs/recommended-with-jsonc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export = {
"jsonc/no-dupe-keys": "error",
"jsonc/no-multi-str": "error",
"jsonc/no-number-props": "error",
"jsonc/no-numeric-separators": "error",
"jsonc/no-regexp-literals": "error",
"jsonc/no-sparse-arrays": "error",
"jsonc/no-template-literals": "error",
Expand Down
Loading