refactor: lint options

This commit is contained in:
liyasthomas
2021-05-25 21:43:13 +05:30
parent 2e213a8692
commit baf6d6bd29
11 changed files with 174 additions and 96 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
. "$(dirname $0)/_/husky.sh" . "$(dirname "$0")/_/husky.sh"
npm run pre-commit npm run pre-commit

View File

@@ -1,3 +0,0 @@
{
"semi": false
}

3
.prettierrc.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
semi: false
}

View File

@@ -1,224 +1,249 @@
/* fallback */ /* fallback */
@font-face { @font-face {
font-family: 'Material Icons'; font-family: "Material Icons";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Material_Icons-400-fallback1.woff2') format('woff2'); src: url("~assets/fonts/Material_Icons-400-fallback1.woff2") format("woff2");
} }
/* devanagari */ /* devanagari */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-400-devanagari2.woff2') format('woff2'); src: url("~assets/fonts/Poppins-400-devanagari2.woff2") format("woff2");
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8,
U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-400-latin-ext3.woff2') format('woff2'); src: url("~assets/fonts/Poppins-400-latin-ext3.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-400-latin4.woff2') format('woff2'); src: url("~assets/fonts/Poppins-400-latin4.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
/* devanagari */ /* devanagari */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-500-devanagari5.woff2') format('woff2'); src: url("~assets/fonts/Poppins-500-devanagari5.woff2") format("woff2");
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8,
U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-500-latin-ext6.woff2') format('woff2'); src: url("~assets/fonts/Poppins-500-latin-ext6.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-500-latin7.woff2') format('woff2'); src: url("~assets/fonts/Poppins-500-latin7.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
/* devanagari */ /* devanagari */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-600-devanagari8.woff2') format('woff2'); src: url("~assets/fonts/Poppins-600-devanagari8.woff2") format("woff2");
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8,
U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-600-latin-ext9.woff2') format('woff2'); src: url("~assets/fonts/Poppins-600-latin-ext9.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-600-latin10.woff2') format('woff2'); src: url("~assets/fonts/Poppins-600-latin10.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
/* devanagari */ /* devanagari */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 700; font-weight: 700;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-700-devanagari11.woff2') format('woff2'); src: url("~assets/fonts/Poppins-700-devanagari11.woff2") format("woff2");
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8,
U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 700; font-weight: 700;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-700-latin-ext12.woff2') format('woff2'); src: url("~assets/fonts/Poppins-700-latin-ext12.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 700; font-weight: 700;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-700-latin13.woff2') format('woff2'); src: url("~assets/fonts/Poppins-700-latin13.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
/* devanagari */ /* devanagari */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 800; font-weight: 800;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-800-devanagari14.woff2') format('woff2'); src: url("~assets/fonts/Poppins-800-devanagari14.woff2") format("woff2");
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8,
U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 800; font-weight: 800;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-800-latin-ext15.woff2') format('woff2'); src: url("~assets/fonts/Poppins-800-latin-ext15.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Poppins'; font-family: "Poppins";
font-style: normal; font-style: normal;
font-weight: 800; font-weight: 800;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Poppins-800-latin16.woff2') format('woff2'); src: url("~assets/fonts/Poppins-800-latin16.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
/* cyrillic-ext */ /* cyrillic-ext */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-cyrillic-ext17.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-cyrillic-ext17.woff2") format("woff2");
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F,
U+FE2E-FE2F;
} }
/* cyrillic */ /* cyrillic */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-cyrillic18.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-cyrillic18.woff2") format("woff2");
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
} }
/* greek */ /* greek */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-greek19.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-greek19.woff2") format("woff2");
unicode-range: U+0370-03FF; unicode-range: U+0370-03FF;
} }
/* vietnamese */ /* vietnamese */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-vietnamese20.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-vietnamese20.woff2") format("woff2");
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
U+01AF-01B0, U+1EA0-1EF9, U+20AB;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-latin-ext21.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-latin-ext21.woff2") format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Roboto Mono'; font-family: "Roboto Mono";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url('~assets/fonts/Roboto_Mono-400-latin22.woff2') format('woff2'); src: url("~assets/fonts/Roboto_Mono-400-latin22.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
} }
.material-icons { .material-icons {
font-family: 'Material Icons'; font-family: "Material Icons"; /* stylelint-disable-line font-family-no-missing-generic-family-keyword */
font-weight: normal; font-weight: normal;
font-style: normal; font-style: normal;
font-size: 24px; font-size: 24px;
@@ -229,6 +254,6 @@
white-space: nowrap; white-space: nowrap;
word-wrap: normal; word-wrap: normal;
direction: ltr; direction: ltr;
-webkit-font-feature-settings: 'liga'; -webkit-font-feature-settings: "liga";
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
} }

View File

@@ -1,5 +1,6 @@
/* purgecss start ignore */ /* purgecss start ignore */
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
/* purgecss end ignore */ /* purgecss end ignore */
@tailwind utilities; @tailwind utilities;

View File

@@ -99,7 +99,7 @@ import {
toggleGraphqlHistoryEntryStar, toggleGraphqlHistoryEntryStar,
toggleRESTHistoryEntryStar, toggleRESTHistoryEntryStar,
deleteGraphqlHistoryEntry, deleteGraphqlHistoryEntry,
deleteRESTHistoryEntry deleteRESTHistoryEntry,
} from "~/newstore/history" } from "~/newstore/history"
export default { export default {
@@ -116,7 +116,7 @@ export default {
}, },
subscriptions() { subscriptions() {
return { return {
history: this.page === "rest" ? restHistory$ : graphqlHistory$ history: this.page === "rest" ? restHistory$ : graphqlHistory$,
} }
}, },
computed: { computed: {

View File

@@ -36,6 +36,7 @@ const axiosWithProxy = async (req) => {
} catch (e) { } catch (e) {
// Check if the throw is due to a cancellation // Check if the throw is due to a cancellation
if (axios.isCancel(e)) { if (axios.isCancel(e)) {
// eslint-disable-next-line no-throw-literal
throw "cancellation" throw "cancellation"
} else { } else {
throw e throw e
@@ -54,6 +55,7 @@ const axiosWithoutProxy = async (req, _store) => {
return res return res
} catch (e) { } catch (e) {
if (axios.isCancel(e)) { if (axios.isCancel(e)) {
// eslint-disable-next-line no-throw-literal
throw "cancellation" throw "cancellation"
} else { } else {
throw e throw e

View File

@@ -1,3 +1,5 @@
/* eslint-disable */
import infer from "tern/lib/infer" import infer from "tern/lib/infer"
import tern from "tern/lib/tern" import tern from "tern/lib/tern"
@@ -69,7 +71,8 @@ function makeVisitors(server, query, file, messages) {
var expr = tern.findQueryExpr(file, query) var expr = tern.findQueryExpr(file, query)
var type = infer.expressionType(expr) var type = infer.expressionType(expr)
var objExpr = type.getType() var objExpr = type.getType()
if (objExpr && objExpr.originNode) return getNodeValue(objExpr.originNode) if (objExpr && objExpr.originNode)
return getNodeValue(objExpr.originNode)
return null return null
} }
return node.value return node.value
@@ -146,7 +149,8 @@ function makeVisitors(server, query, file, messages) {
if (!expectedType || !actualType) return true if (!expectedType || !actualType) return true
var currentProto = actualType.proto var currentProto = actualType.proto
while (currentProto) { while (currentProto) {
if (expectedType.proto && expectedType.proto.name === currentProto.name) return true if (expectedType.proto && expectedType.proto.name === currentProto.name)
return true
currentProto = currentProto.proto currentProto = currentProto.proto
} }
return false return false
@@ -283,7 +287,10 @@ function makeVisitors(server, query, file, messages) {
} }
} }
} else { } else {
var actualArg = infer.expressionType({ node: actualNode, state: state }) var actualArg = infer.expressionType({
node: actualNode,
state: state,
})
// if actual type is an Object literal and expected type is an object, we ignore // if actual type is an Object literal and expected type is an object, we ignore
// the comparison type since object literal properties validation is done inside "ObjectExpression". // the comparison type since object literal properties validation is done inside "ObjectExpression".
if (!(expectedArg.getObjType() && isObjectLiteral(actualArg))) { if (!(expectedArg.getObjType() && isObjectLiteral(actualArg))) {
@@ -328,7 +335,11 @@ function makeVisitors(server, query, file, messages) {
function isUsedVariable(varNode, varState, file, srv) { function isUsedVariable(varNode, varState, file, srv) {
var name = varNode.name var name = varNode.name
for (var scope = varState; scope && !(name in scope.props); scope = scope.prev) {} for (
var scope = varState;
scope && !(name in scope.props);
scope = scope.prev
) {}
if (!scope) return false if (!scope) return false
var hasRef = false var hasRef = false
@@ -350,7 +361,8 @@ function makeVisitors(server, query, file, messages) {
infer.findRefs(file.ast, file.scope, name, scope, searchRef(file)) infer.findRefs(file.ast, file.scope, name, scope, searchRef(file))
for (var i = 0; i < srv.files.length && !hasRef; ++i) { for (var i = 0; i < srv.files.length && !hasRef; ++i) {
var cur = srv.files[i] var cur = srv.files[i]
if (cur != file) infer.findRefs(cur.ast, cur.scope, name, scope, searchRef(cur)) if (cur != file)
infer.findRefs(cur.ast, cur.scope, name, scope, searchRef(cur))
} }
} }
} catch (e) {} } catch (e) {}
@@ -374,14 +386,18 @@ function makeVisitors(server, query, file, messages) {
unusedRule.severity unusedRule.severity
) )
// type mismatch? // type mismatch?
if (mismatchRule) validateAssignement(varNode, decl.init, mismatchRule, state) if (mismatchRule)
validateAssignement(varNode, decl.init, mismatchRule, state)
} }
} }
break break
case "FunctionDeclaration": case "FunctionDeclaration":
if (unusedRule) { if (unusedRule) {
var varNode = node.id var varNode = node.id
if (varNode.name != "✖" && !isUsedVariable(varNode, state, file, server)) if (
varNode.name != "✖" &&
!isUsedVariable(varNode, state, file, server)
)
addMessage( addMessage(
varNode, varNode,
"Unused function '" + getNodeName(varNode) + "'", "Unused function '" + getNodeName(varNode) + "'",
@@ -410,7 +426,10 @@ function makeVisitors(server, query, file, messages) {
var rule = getRule("MixedReturnTypes") var rule = getRule("MixedReturnTypes")
if (!rule) return if (!rule) return
if (state.fnType && state.fnType.retval) { if (state.fnType && state.fnType.retval) {
var actualType = infer.expressionType({ node: node.argument, state: state }), var actualType = infer.expressionType({
node: node.argument,
state: state,
}),
expectedType = state.fnType.retval expectedType = state.fnType.retval
if (!compareType(expectedType, actualType)) { if (!compareType(expectedType, actualType)) {
addMessage( addMessage(
@@ -458,14 +477,21 @@ function makeVisitors(server, query, file, messages) {
// this may contain properties that are not really defined. // this may contain properties that are not really defined.
parentType.types.forEach(function (potentialType) { parentType.types.forEach(function (potentialType) {
// Obj#hasProp checks the prototype as well // Obj#hasProp checks the prototype as well
if (typeof potentialType.hasProp == "function" && potentialType.hasProp(prop, true)) { if (
typeof potentialType.hasProp == "function" &&
potentialType.hasProp(prop, true)
) {
propertyDefined = true propertyDefined = true
} }
}) })
} }
if (!propertyDefined) { if (!propertyDefined) {
addMessage(node, "Unknown property '" + getNodeName(node) + "'", rule.severity) addMessage(
node,
"Unknown property '" + getNodeName(node) + "'",
rule.severity
)
} }
} }
}, },
@@ -482,7 +508,11 @@ function makeVisitors(server, query, file, messages) {
} else if (type.isEmpty()) { } else if (type.isEmpty()) {
// The type of the identifier cannot be determined, // The type of the identifier cannot be determined,
// and the origin is unknown. // and the origin is unknown.
addMessage(node, "Unknown identifier '" + getNodeName(node) + "'", rule.severity) addMessage(
node,
"Unknown identifier '" + getNodeName(node) + "'",
rule.severity
)
} else { } else {
// Even though the origin node is unknown, the type is known. // Even though the origin node is unknown, the type is known.
// This is typically the case for built-in identifiers (e.g. window or document). // This is typically the case for built-in identifiers (e.g. window or document).
@@ -502,7 +532,10 @@ function makeVisitors(server, query, file, messages) {
var rule = getRule("ObjectLiteral") var rule = getRule("ObjectLiteral")
if (!rule) return if (!rule) return
var actualType = node.objType var actualType = node.objType
var ctxType = infer.typeFromContext(file.ast, { node: node, state: state }), var ctxType = infer.typeFromContext(file.ast, {
node: node,
state: state,
}),
expectedType = null expectedType = null
if (ctxType instanceof infer.Obj) { if (ctxType instanceof infer.Obj) {
expectedType = ctxType.getObjType() expectedType = ctxType.getObjType()
@@ -522,7 +555,10 @@ function makeVisitors(server, query, file, messages) {
var rule = getRule("Array") var rule = getRule("Array")
if (!rule) return if (!rule) return
//var actualType = infer.expressionType({node: node, state: state}); //var actualType = infer.expressionType({node: node, state: state});
var ctxType = infer.typeFromContext(file.ast, { node: node, state: state }), var ctxType = infer.typeFromContext(file.ast, {
node: node,
state: state,
}),
expectedType = getArrType(ctxType) expectedType = getArrType(ctxType)
if (expectedType /*&& expectedType != actualType*/) { if (expectedType /*&& expectedType != actualType*/) {
// expected type is known. Ex: config object of RequireJS // expected type is known. Ex: config object of RequireJS
@@ -540,7 +576,11 @@ function makeVisitors(server, query, file, messages) {
// Validate ES6 modules "from" // Validate ES6 modules "from"
var modType = me.getModType(source) var modType = me.getModType(source)
if (!modType) { if (!modType) {
addMessage(source, "Invalid modules from '" + source.value + "'", rule.severity) addMessage(
source,
"Invalid modules from '" + source.value + "'",
rule.severity
)
return return
} }
// Validate ES6 modules "specifiers" // Validate ES6 modules "specifiers"
@@ -636,7 +676,8 @@ export function validateFiles(server, query) {
state = file.scope state = file.scope
var visitors = makeVisitors(server, query, file, messagesFile) var visitors = makeVisitors(server, query, file, messagesFile)
walk.simple(ast, visitors, infer.searchVisitor, state) walk.simple(ast, visitors, infer.searchVisitor, state)
if (groupByFiles) messages.push({ file: file.name, messages: messagesFile }) if (groupByFiles)
messages.push({ file: file.name, messages: messagesFile })
} }
return { messages: messages } return { messages: messages }
} catch (err) { } catch (err) {
@@ -655,8 +696,14 @@ var getLint = (tern.getLint = function (name) {
function getRules(options) { function getRules(options) {
var rules = {} var rules = {}
for (var ruleName in defaultRules) { for (var ruleName in defaultRules) {
if (options && options.rules && options.rules[ruleName] && options.rules[ruleName].severity) { if (
if (options.rules[ruleName].severity != "none") rules[ruleName] = options.rules[ruleName] options &&
options.rules &&
options.rules[ruleName] &&
options.rules[ruleName].severity
) {
if (options.rules[ruleName].severity != "none")
rules[ruleName] = options.rules[ruleName]
} else { } else {
rules[ruleName] = defaultRules[ruleName] rules[ruleName] = defaultRules[ruleName]
} }
@@ -667,6 +714,9 @@ function getRules(options) {
function getRule(ruleName) { function getRule(ruleName) {
const cx = infer.cx() const cx = infer.cx()
const server = cx.parent const server = cx.parent
const rules = server && server._lint && server._lint.rules ? server._lint.rules : defaultRules const rules =
server && server._lint && server._lint.rules
? server._lint.rules
: defaultRules
return rules[ruleName] return rules[ruleName]
} }

View File

@@ -10,17 +10,17 @@
"start": "nuxt start", "start": "nuxt start",
"generate": "nuxt generate --modern", "generate": "nuxt generate --modern",
"analyze": "npx nuxt build -a", "analyze": "npx nuxt build -a",
"lint:js": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .", "lint:script": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .",
"lint:style": "stylelint **/*.{vue,css} --ignore-path .gitignore", "lint:style": "stylelint **/*.{css,scss,vue} --ignore-path .gitignore",
"lint": "npm run lint:js && npm run lint:style", "lint": "npm run lint:script && npm run lint:style",
"lintfix": "eslint --ext .ts,.js,.vue --ignore-path .gitignore . --fix", "lintfix": "eslint --ext .ts,.js,.vue --ignore-path .gitignore . --fix",
"test": "jest", "test": "jest",
"postinstall": "husky install", "prepare": "husky install",
"pre-commit": "lint-staged" "pre-commit": "lint-staged"
}, },
"lint-staged": { "lint-staged": {
"*.{ts,js,vue}": "eslint", "*.{ts,js,vue}": "eslint",
"*.{css,vue}": "stylelint" "*.{css,scss,vue}": "stylelint"
}, },
"dependencies": { "dependencies": {
"@apollo/client": "^3.3.19", "@apollo/client": "^3.3.19",