Skip to content

Commit

Permalink
style: eqeqeq
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Aug 11, 2020
1 parent 99c2b28 commit dd5a08b
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Expand Up @@ -39,6 +39,7 @@ rules:
curly: [error, multi-line, consistent]
dot-location: [error, property]
dot-notation: error
eqeqeq: [error, smart]
id-match: error
linebreak-style: [error, unix]
new-cap: error
Expand Down Expand Up @@ -68,5 +69,4 @@ rules:
no-control-regex: 0
no-useless-escape: error
no-void: error
# eqeqeq: [error, smart]
# no-var: error
8 changes: 4 additions & 4 deletions lib/ajv.js
Expand Up @@ -73,7 +73,7 @@ function Ajv(opts) {

opts.loopRequired = opts.loopRequired || Infinity
opts.loopEnum = opts.loopEnum || Infinity
if (opts.errorDataPath == "property") opts._errorDataPathProperty = true
if (opts.errorDataPath === "property") opts._errorDataPathProperty = true
if (opts.serialize === undefined) opts.serialize = stableStringify
this._metaOpts = getMetaSchemaOptions(this)

Expand Down Expand Up @@ -185,7 +185,7 @@ function validateSchema(schema, throwOrLogError) {
var valid = this.validate($schema, schema)
if (!valid && throwOrLogError) {
var message = "schema is invalid: " + this.errorsText()
if (this._opts.validateSchema == "log") this.logger.error(message)
if (this._opts.validateSchema === "log") this.logger.error(message)
else throw new Error(message)
}
return valid
Expand Down Expand Up @@ -314,7 +314,7 @@ function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
var recursiveMeta
if (
willValidate &&
!(recursiveMeta = id && id == resolve.normalizeId(schema.$schema))
!(recursiveMeta = id && id === resolve.normalizeId(schema.$schema))
) {
this.validateSchema(schema, true)
}
Expand All @@ -329,7 +329,7 @@ function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
meta: meta,
})

if (id[0] != "#" && shouldAddSchema) this._refs[id] = schemaObj
if (id[0] !== "#" && shouldAddSchema) this._refs[id] = schemaObj
this._cache.put(cacheKey, schemaObj)

if (willValidate && recursiveMeta) this.validateSchema(schema, true)
Expand Down
8 changes: 4 additions & 4 deletions lib/compile/index.js
Expand Up @@ -78,8 +78,8 @@ function compile(schema, root, localRefs, baseId) {
}

function localCompile(_schema, _root, localRefs, baseId) {
var isRoot = !_root || (_root && _root.schema == _schema)
if (_root.schema != root.schema) {
var isRoot = !_root || (_root && _root.schema === _schema)
if (_root.schema !== root.schema) {
return compile.call(self, _schema, _root, localRefs, baseId)
}

Expand Down Expand Up @@ -279,7 +279,7 @@ function compile(schema, root, localRefs, baseId) {
var message =
"keyword schema is invalid: " +
self.errorsText(validateSchema.errors)
if (self._opts.validateSchema == "log") self.logger.error(message)
if (self._opts.validateSchema === "log") self.logger.error(message)
else throw new Error(message)
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ function compIndex(schema, root, baseId) {
/* jshint validthis: true */
for (var i = 0; i < this._compilations.length; i++) {
var c = this._compilations[i]
if (c.schema == schema && c.root == root && c.baseId == baseId) return i
if (c.schema === schema && c.root === root && c.baseId === baseId) return i
}
return -1
}
Expand Down
16 changes: 8 additions & 8 deletions lib/compile/resolve.js
Expand Up @@ -80,7 +80,7 @@ function resolveSchema(root, ref) {
refVal = this._schemas[id]
if (refVal instanceof SchemaObject) {
if (!refVal.validate) this._compile(refVal)
if (id == normalizeId(ref)) {
if (id === normalizeId(ref)) {
return {schema: refVal, root: root, baseId: baseId}
}
root = refVal
Expand Down Expand Up @@ -119,7 +119,7 @@ var PREVENT_SCOPE_CHANGE = toHash([
function getJsonPointer(parsedRef, baseId, schema, root) {
/* jshint validthis: true */
parsedRef.fragment = parsedRef.fragment || ""
if (parsedRef.fragment.slice(0, 1) != "/") return
if (parsedRef.fragment.slice(0, 1) !== "/") return
var parts = parsedRef.fragment.split("/")

for (var i = 1; i < parts.length; i++) {
Expand Down Expand Up @@ -181,7 +181,7 @@ function checkNoRef(schema) {
}
} else {
for (var key in schema) {
if (key == "$ref") return false
if (key === "$ref") return false
item = schema[key]
if (typeof item == "object" && !checkNoRef(item)) return false
}
Expand All @@ -196,17 +196,17 @@ function countKeys(schema) {
for (var i = 0; i < schema.length; i++) {
item = schema[i]
if (typeof item == "object") count += countKeys(item)
if (count == Infinity) return Infinity
if (count === Infinity) return Infinity
}
} else {
for (var key in schema) {
if (key == "$ref") return Infinity
if (key === "$ref") return Infinity
if (SIMPLE_INLINED[key]) {
count++
} else {
item = schema[key]
if (typeof item == "object") count += countKeys(item) + 1
if (count == Infinity) return Infinity
if (count === Infinity) return Infinity
}
}
}
Expand Down Expand Up @@ -272,8 +272,8 @@ function resolveIds(schema) {
if (!equal(sch, refVal.schema)) {
throw new Error('id "' + id + '" resolves to more than one schema')
}
} else if (id != normalizeId(fullPath)) {
if (id[0] == "#") {
} else if (id !== normalizeId(fullPath)) {
if (id[0] === "#") {
if (localRefs[id] && !equal(sch, localRefs[id])) {
throw new Error(
'id "' + id + '" resolves to more than one schema'
Expand Down
4 changes: 2 additions & 2 deletions lib/compile/util.ts
Expand Up @@ -151,7 +151,7 @@ export function schemaHasRulesExcept(
exceptKeyword: string
): boolean | undefined {
if (typeof schema == "boolean") return !schema && exceptKeyword !== "not"
for (const key in schema) if (key != exceptKeyword && rules[key]) return true
for (const key in schema) if (key !== exceptKeyword && rules[key]) return true
}

// TODO rules, schema?
Expand Down Expand Up @@ -209,7 +209,7 @@ export function getData($data: string, lvl: number, paths: string[]): string {
if (!matches) throw new Error("Invalid JSON-pointer: " + $data)
const up: number = +matches[1]
jsonPointer = matches[2]
if (jsonPointer == "#") {
if (jsonPointer === "#") {
if (up >= lvl) {
throw new Error(
"Cannot access property/index " +
Expand Down
4 changes: 2 additions & 2 deletions lib/keyword.ts
Expand Up @@ -102,7 +102,7 @@ export function addKeyword(
var ruleGroup
for (var i = 0; i < RULES.length; i++) {
var rg = RULES[i]
if (rg.type == dataType) {
if (rg.type === dataType) {
ruleGroup = rg
break
}
Expand Down Expand Up @@ -265,7 +265,7 @@ export function removeKeyword(keyword: string): object {
for (var i = 0; i < RULES.length; i++) {
var rules = RULES[i].rules
for (var j = 0; j < rules.length; j++) {
if (rules[j].keyword == keyword) {
if (rules[j].keyword === keyword) {
rules.splice(j, 1)
break
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/bundle.js
Expand Up @@ -10,7 +10,7 @@ var pkg = process.argv[2],
compress = process.argv[4]

var packageDir = path.join(__dirname, "..")
if (pkg != ".") packageDir = path.join(packageDir, "node_modules", pkg)
if (pkg !== ".") packageDir = path.join(packageDir, "node_modules", pkg)

var json = require(path.join(packageDir, "package.json"))

Expand Down Expand Up @@ -47,7 +47,7 @@ browserify(bOpts)
var compressOpts = compress.split(",")
for (var i = 0, il = compressOpts.length; i < il; ++i) {
var pair = compressOpts[i].split("=")
uglifyOpts.compress[pair[0]] = pair.length < 1 || pair[1] != "false"
uglifyOpts.compress[pair[0]] = pair.length < 1 || pair[1] !== "false"
}
}
if (standalone) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/compile-dots.js
Expand Up @@ -67,7 +67,7 @@ files.forEach((f) => {
v = v.replace(/\$/g, "\\$$")
var regexp = new RegExp(v + "[^A-Za-z0-9_$]", "g")
var count = occurrences(regexp)
if (count == 1) {
if (count === 1) {
regexp = new RegExp("var\\s+" + v + "\\s*=[^;]+;|var\\s+" + v + ";")
code = code.replace(regexp, "")
}
Expand All @@ -76,7 +76,7 @@ files.forEach((f) => {
function removeAlwaysFalsyInOr() {
var countUsed = occurrences(ERROR_KEYWORD)
var countOr = occurrences(ERROR_KEYWORD_OR)
if (countUsed == countOr + 1) code = code.replace(ERROR_KEYWORD_OR, "")
if (countUsed === countOr + 1) code = code.replace(ERROR_KEYWORD_OR, "")
}

function occurrences(regexp) {
Expand Down
2 changes: 1 addition & 1 deletion spec/async.spec.js
Expand Up @@ -196,7 +196,7 @@ describe("compileAsync method", () => {
ajv.addKeyword("myFooBar", {
type: "string",
validate: function (sch, data) {
return sch == data
return sch === data
},
})

Expand Down
4 changes: 2 additions & 2 deletions spec/async_schemas.spec.js
Expand Up @@ -63,9 +63,9 @@ function addAsyncFormatsAndKeywords(ajv) {
}

function checkWordOnServer(str) {
return str == "tomorrow"
return str === "tomorrow"
? Promise.resolve(true)
: str == "manana"
: str === "manana"
? Promise.resolve(false)
: Promise.reject(new Error("unknown word"))
}
Expand Down
6 changes: 3 additions & 3 deletions spec/async_validate.spec.js
Expand Up @@ -406,9 +406,9 @@ describe("async schemas, formats and keywords", function () {
})

function checkWordOnServer(str) {
return str == "tomorrow"
return str === "tomorrow"
? Promise.resolve(true)
: str == "manana"
: str === "manana"
? Promise.resolve(false)
: Promise.reject(new Error("unknown word"))
}
Expand Down Expand Up @@ -455,7 +455,7 @@ function checkNotValid(p) {
})
.catch((err) => {
err.should.be.instanceof(Error)
if (err.message == SHOULD_BE_INVALID) throw err
if (err.message === SHOULD_BE_INVALID) throw err
return err
})
}
Expand Down
2 changes: 1 addition & 1 deletion spec/browser_test_suite.js
Expand Up @@ -2,7 +2,7 @@

module.exports = function (suite) {
suite.forEach((file) => {
if (file.name.indexOf("optional/format") == 0) {
if (file.name.indexOf("optional/format") === 0) {
file.name = file.name.replace("optional/", "")
}
file.test = file.module
Expand Down
6 changes: 3 additions & 3 deletions spec/custom.spec.js
Expand Up @@ -364,7 +364,7 @@ describe("Custom keywords", () => {
for (var prop in _schema) {
var path = prop.split(".")
var properties = {}
if (path.length == 1) {
if (path.length === 1) {
properties[prop] = _schema[prop]
} else {
var deepProperties = {}
Expand All @@ -374,7 +374,7 @@ describe("Custom keywords", () => {
expanded.push({properties: properties})
}

return expanded.length == 1 ? expanded[0] : {allOf: expanded}
return expanded.length === 1 ? expanded[0] : {allOf: expanded}
}
})
})
Expand Down Expand Up @@ -983,7 +983,7 @@ describe("Custom keywords", () => {
function validateRangeSchema(schema, parentSchema) {
var schemaValid =
Array.isArray(schema) &&
schema.length == 2 &&
schema.length === 2 &&
typeof schema[0] == "number" &&
typeof schema[1] == "number"
if (!schemaValid) {
Expand Down
16 changes: 8 additions & 8 deletions spec/errors.spec.js
Expand Up @@ -118,9 +118,9 @@ describe("Validation errors", () => {
{additionalProperty: "quux"}
)

if (errorDataPath == "property") {
if (errorDataPath === "property") {
fullValidate.errors
.filter((err) => err.keyword == "additionalProperties")
.filter((err) => err.keyword === "additionalProperties")
.map((err) =>
fullAjv._opts.jsonPointers
? err.dataPath.substr(1)
Expand Down Expand Up @@ -607,20 +607,20 @@ describe("Validation errors", () => {

function pathFunc(errorDataPath) {
return function (dataPath) {
return errorDataPath == "property" ? dataPath : ""
return errorDataPath === "property" ? dataPath : ""
}
}

function requiredFunc(errorDataPath) {
return function (prop) {
return errorDataPath == "property"
return errorDataPath === "property"
? "is a required property"
: "should have required property '" + prop + "'"
}
}

function additionalFunc(errorDataPath) {
return errorDataPath == "property"
return errorDataPath === "property"
? "is an invalid additional property"
: "should NOT have additional properties"
}
Expand Down Expand Up @@ -798,7 +798,7 @@ describe("Validation errors", () => {
"",
"property name 'foo' is invalid"
)
if (numErrors == 4) {
if (numErrors === 4) {
shouldBeError(
validate.errors[2],
"pattern",
Expand Down Expand Up @@ -1112,7 +1112,7 @@ describe("Validation errors", () => {
{multipleOf: multipleOf}
)

if (numErrors == 2) {
if (numErrors === 2) {
err = validate.errors[1]
shouldBeError(
err,
Expand Down Expand Up @@ -1150,7 +1150,7 @@ describe("Validation errors", () => {
var expectedErrors = _ajv._opts.allErrors ? 2 : 1
shouldBeInvalid(validate, [1, "2", "2", 2], expectedErrors)
testTypeError(0, "/1")
if (expectedErrors == 2) testTypeError(1, "/2")
if (expectedErrors === 2) testTypeError(1, "/2")

function testTypeError(i, dataPath) {
var err = validate.errors[i]
Expand Down
4 changes: 2 additions & 2 deletions spec/options/useDefaults.spec.js
Expand Up @@ -155,9 +155,9 @@ describe("useDefaults options", () => {
var data2 = {}
validate(data2).should.equal(true)

if (useDefaultsMode == "reference") {
if (useDefaultsMode === "reference") {
data2.items.should.eql(["a-default", "another-value"])
} else if (useDefaultsMode == "value") {
} else if (useDefaultsMode === "value") {
data2.items.should.eql(["a-default"])
} else {
throw new Error("unknown useDefaults mode")
Expand Down

0 comments on commit dd5a08b

Please sign in to comment.