Skip to content

Commit

Permalink
Merge pull request #595 from chantouchsek/dependabot/npm_and_yarn/ant…
Browse files Browse the repository at this point in the history
…fu/eslint-config-1.0.0

chore(deps-dev): bump @antfu/eslint-config from 0.43.1 to 1.0.0
  • Loading branch information
chantouchsek authored Nov 1, 2023
2 parents a0e9afe + 75c12c7 commit 8d3a564
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 569 deletions.
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/alpha.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('alpha validation rule', () => {
expect(validator.passes()).toBeFalsy()
})

it('should fail with non-alphabetic characters', () => {
it('should fail with non alphabetic characters', () => {
const validator = new Validator({ name: 12 }, { name: 'alpha' })
expect(validator.fails()).toBeTruthy()
expect(validator.passes()).toBeFalsy()
Expand Down
6 changes: 0 additions & 6 deletions __tests__/confirmed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('confirmed validation rule', () => {
it('should fail without a matching confirmation field for the field under validation', () => {
const validator = new Validator({ password: 'abc' }, { password: 'confirmed' })
expect(validator.passes()).toBeFalsy()
expect(validator.fails()).toBeTruthy()
})

it('should fail without a matching confirmation field for the field under validation', () => {
const validator = new Validator({ password: 'abc', password_confirmation: 'abcd' }, { password: 'confirmed' })
expect(validator.passes()).toBeFalsy()
Expand Down
10 changes: 2 additions & 8 deletions __tests__/custom-attributes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Validator custom attribute', () => {
describe('validator custom attribute', () => {
it('should be able set custom attributes', () => {
const validator = new Validator(
{ form: { name: null } },
Expand All @@ -17,13 +17,7 @@ describe('Validator custom attribute', () => {
expect(validator.passes()).not.toBeTruthy()
expect(validator.errors.first('form.name')).toEqual('The Username need to be filled.')
})
it('should be able get custom attribute', () => {
const validator = new Validator({ form: { name: null } }, { form: { name: 'required', age: 'required' } })
expect(validator.fails()).toBeTruthy()
expect(validator.passes()).not.toBeTruthy()
expect(validator.errors.first('form.name')).toEqual('The form name field is required.')
expect(validator.errors.first('form.age')).toEqual('The form age field is required.')
})

it('should be able get custom attribute', () => {
const validator = new Validator(
{ form: { name: null } },
Expand Down
23 changes: 2 additions & 21 deletions __tests__/custom-messages.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Validator custom messages', () => {
describe('validator custom messages', () => {
it('override the default message for the validator', () => {
const validator = new Validator(
{ name: '' },
Expand All @@ -17,23 +17,6 @@ describe('Validator custom messages', () => {
expect(validator.errors.first('name')).toEqual('Name is missing.')
})

it('override the default message for a type of the validator', () => {
const validator = new Validator(
{ name: 'A' },
{ name: 'min:4' },
{
customMessages: {
min: {
string: ':attribute is not long enough. Should be :min.',
},
},
},
)
expect(validator.fails()).toBeTruthy()
expect(validator.errors.get('name').length).toEqual(1)
expect(validator.errors.first('name')).toEqual('name is not long enough. Should be 4.')
})

it('override the default message for the validator with several :attribute in message', () => {
const validator = new Validator(
{ name: '' },
Expand All @@ -52,9 +35,7 @@ describe('Validator custom messages', () => {
it('override the default message for a type of the validator', () => {
const validator = new Validator(
{ name: 'A' },
{
name: 'min:4',
},
{ name: 'min:4' },
{
customMessages: {
min: {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/error-count.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Error counts', () => {
describe('error counts', () => {
it('should return 0 when validation has not yet run', () => {
const validator = new Validator({ username: '' }, { username: 'required' })
expect(validator.errorCount).toEqual(0)
Expand Down
6 changes: 3 additions & 3 deletions __tests__/error-messages.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Error messages', () => {
describe('error messages', () => {
describe('first()', () => {
it('should return an error message that states the email is required', () => {
const validator = new Validator({ email: '' }, { email: 'required|email' })
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('Error messages', () => {
})
})

describe('ValidatorErrors.prototype.all()', () => {
describe('validatorErrors.prototype.all()', () => {
it('should return an array of all email error messages', () => {
const validation = new Validator(
{ name: 'd', email: '', age: 28 },
Expand All @@ -187,7 +187,7 @@ describe('Error messages', () => {
})
})

describe('ValidatorErrors.prototype.has()', () => {
describe('validatorErrors.prototype.has()', () => {
it('should return an array of all email error messages', () => {
const validation = new Validator(
{ name: 'd', email: '', age: 28 },
Expand Down
2 changes: 1 addition & 1 deletion __tests__/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Errors', () => {
describe('errors', () => {
it('should get all errors message', () => {
const validator = new Validator(null, { name: 'required' })
expect(validator.fails()).toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/flatten-object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { flattenObject, isEmpty } from '../src/utils'

describe('Object', () => {
describe('object', () => {
it('should correctly flatten nested object', () => {
const asserts = [
[undefined, {}],
Expand Down
2 changes: 1 addition & 1 deletion __tests__/in.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('in validation rule', () => {
expect(validator.errors.first('state')).toEqual('The selected state is invalid.')
})

it('should pass when the value is in the set of comma separated values', () => {
it('should pass when the string value is in the set of comma separated values', () => {
const validator = new Validator({ state: 'CA' }, { state: 'in:CA,TX,FL' })
expect(validator.passes()).toBeTruthy()
expect(validator.fails()).toBeFalsy()
Expand Down
20 changes: 4 additions & 16 deletions __tests__/ip.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('IP Validation rules', () => {
describe('IPv4 Validation rule', () => {
describe('iP Validation rules', () => {
describe('iPv4 Validation rule', () => {
it('should pass localhost ipv4 addres', () => {
const validator = new Validator(
{
Expand Down Expand Up @@ -51,18 +51,6 @@ describe('IP Validation rules', () => {
expect(validator.passes()).toBeFalsy()
})

it('should fail ip address containing non integer octants', () => {
const validator = new Validator(
{
ipAddr: '192.fail.33.10',
},
{
ipAddr: 'ipv4',
},
)
expect(validator.passes()).toBeFalsy()
})

it('should fail ip address more than 4 octants', () => {
const validator = new Validator(
{
Expand Down Expand Up @@ -124,7 +112,7 @@ describe('IP Validation rules', () => {
})
})

describe('IPv6 Validation rule', () => {
describe('iPv6 Validation rule', () => {
it('should pass normal ipv6 address ', () => {
const validator = new Validator(
{
Expand Down Expand Up @@ -329,7 +317,7 @@ describe('IP Validation rules', () => {
})
})

describe('IP General Validation rule', () => {
describe('iP General Validation rule', () => {
it('should pass localhost ipv4 addres', () => {
const validator = new Validator(
{
Expand Down
3 changes: 1 addition & 2 deletions __tests__/nested.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ describe('nested validation rules', () => {
{ values: [''], key: testVal },
{ values: [''], key: testVal },
],
},
{
}, {
'filters.*.key': ['required', { in: [testVal] }],
'filters.*.values': ['array', 'required'],
'filters.*.values.*': `required_if:filters.*.key,${testVal}|string`,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/not_in.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('not_in validation rule', () => {
expect(validator.errors.first('username')).toEqual('The selected username is invalid.')
})

it('should pass when the value is not in the set of comma separated values', () => {
it('should pass when the string value is not in the set of comma separated values', () => {
const validator = new Validator({ username: 'skatedav85' }, { username: 'not_in:user1,user2,user3' })
expect(validator.passes()).toBeTruthy()
expect(validator.fails()).toBeFalsy()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { hasOwnProperty } from '../src/utils'

describe('Utils Object', () => {
describe('utils Object', () => {
describe('hasOwnProperty', () => {
it('should hasOwnProperty must be a function', () => {
expect(typeof hasOwnProperty).toBe('function')
Expand Down
6 changes: 3 additions & 3 deletions __tests__/validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Validator constructor', () => {
describe('validator constructor', () => {
let validator: Validator

beforeEach(() => {
Expand All @@ -13,10 +13,10 @@ describe('Validator constructor', () => {
})

it('should expose on window if browser', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
if (typeof window !== 'undefined') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
expect(window.Validator).toBeDefined()
}
Expand Down
6 changes: 3 additions & 3 deletions __tests__/wildcard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest'
import Validator from '../src/main'

describe('Wildcard', () => {
describe('Simple Rules ', () => {
describe('wildcard', () => {
describe('simple Rules ', () => {
it('should have validation a deep level fails', () => {
const validator = new Validator(
{
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Wildcard', () => {
expect(validator.passes()).toBeTruthy()
})
})
describe('Rules with dependent of another field', () => {
describe('rules with dependent of another field', () => {
it('should have validation fail with required_* and show customMessage', () => {
const validator = new Validator(
{
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '@antfu/eslint-config'

export default config({})
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@chantouchsek/validatorjs",
"type": "module",
"version": "1.4.3",
"description": "The validatorjs library makes data validation in JavaScript very easy in both the browser and Node.js.",
"author": {
Expand Down Expand Up @@ -46,14 +47,13 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@antfu/eslint-config": "^0.43.1",
"@antfu/eslint-config": "^1.0.0",
"@commitlint/cli": "^18.2.0",
"@commitlint/config-conventional": "^18.1.0",
"@types/lodash": "^4.14.199",
"@types/node": "^20.8.2",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.10",
"@vitest/coverage-v8": "^0.34.6",
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.28.1",
"eslint": "^8.52.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"node-notifier": "^10.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ export default class Validator {
if (args.length === 0 && hasOwnProperty(obj, key))
return true

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
return hasNested(obj[key], ...args)
}

const keys = attribute.split('.')

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
return hasNested(this.input, ...keys)
}
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"lib": ["ES5", "ES6", "ES2015", "ES2016", "ES2017", "ES2018", "ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"strictNullChecks": true,
"declaration": true,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"strictNullChecks": true
"forceConsistentCasingInFileNames": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*", "coverage"]
Expand Down
Loading

0 comments on commit 8d3a564

Please sign in to comment.