Skip to content
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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
dist/
lib/
node_modules/
jest.config.js
70 changes: 59 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
{
"env": {
"commonjs": true,
"es2021": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 13
},
"rules": {}
"plugins": ["jest", "@typescript-eslint"],
// "extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{"accessibility": "no-public"}
],
// "@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
// "@typescript-eslint/explicit-function-return-type": [
// "error",
// {"allowExpressions": true}
// ],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
// "@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
// "@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
// "@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
/node_modules/

# TypeScript cache
*.tsbuildinfo

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}
53 changes: 53 additions & 0 deletions __tests__/phpcs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import phpcs from '../src/checks/phpcs'
import {expect, test} from '@jest/globals'

test('it returns defaults', () => {
expect(phpcs({}, 'web')).toEqual([
'phpcs',
'--standard=Drupal,DrupalPractice',
'--extensions=php,module,inc,install,test,profile,theme',
'web/modules/custom'
])
})

test('it handles partial inputs', () => {
let command
command = phpcs(
{
standard: 'Drupal',
ignore: 'node_modules'
},
'web'
)
expect(command).toContain('--standard=Drupal')
expect(command).toContain('--ignore=node_modules')

command = phpcs(
{
extensions: 'php,inc'
},
'docroot'
)
expect(command).toContain('--extensions=php,inc')
expect(command).toContain('docroot/modules/custom')
})

test('it can handle single and multiple paths', () => {
let command
command = phpcs(
{
path: 'web/modules/custom'
},
'web'
)
expect(command).toContain('web/modules/custom')

command = phpcs(
{
path: 'web/modules/custom,web/themes/custom'
},
'web'
)
expect(command).toContain('web/modules/custom')
expect(command).toContain('web/themes/custom')
})
65 changes: 65 additions & 0 deletions __tests__/phplint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import phplint from '../src/checks/phplint'
import {expect, test} from '@jest/globals'

test('it returns defaults', () => {
expect(phplint({}, 'web')).toEqual([
'phplint',
'--exclude=vendor',
'--exclude=web/core',
'--exclude=web/modules/contrib',
'--extensions=php',
'--extensions=module',
'--extensions=theme',
'--extensions=engine',
'--extensions=inc',
'--extensions=install'
])
})

test('it returns no options', () => {
expect(phplint({no_default_options: true}, 'web')).toEqual(['phplint'])
expect(
phplint(
{
no_default_options: true,
exclude: 'vendor'
},
'web'
)
).toEqual(['phplint'])
})

test('it handles partial inputs', () => {
let command
command = phplint(
{
exclude: 'vendor,web/themes/contrib'
},
'web'
)
expect(command).toContain('--exclude=vendor')
expect(command).toContain('--exclude=web/themes/contrib')
expect(command).not.toContain('--exclude=web/modules/contrib')

command = phplint(
{
extensions: 'php,inc'
},
'docroot'
)
expect(command).toContain('--extensions=php')
expect(command).toContain('--extensions=inc')
expect(command).not.toContain('--extensions=module')
expect(command).toContain('--exclude=docroot/modules/contrib')

command = phplint(
{
verbose: true,
path: 'web/modules/custom'
},
'docroot'
)
expect(command).toContain('-v')
expect(command).toContain('--exclude=docroot/modules/contrib')
expect(command).toContain('web/modules/custom')
})
45 changes: 45 additions & 0 deletions __tests__/phpmd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import phpmd from '../src/checks/phpmd'
import {expect, test} from '@jest/globals'

test('it returns defaults', () => {
expect(phpmd({}, 'web')).toEqual([
'phpmd',
'web/modules/custom',
'text',
'codesize,naming,unusedcode',
'--suffixes',
'php,module,theme,engine,inc'
])
})

test('it handles partial inputs', () => {
let command
command = phpmd(
{
format: 'json',
ruleset: 'phpmd.xml'
},
'web'
)
expect(command[2]).toEqual('json')
expect(command[3]).toEqual('phpmd.xml')

command = phpmd(
{
suffixes: 'php'
},
'docroot'
)
expect(command[1]).toEqual('docroot/modules/custom')
expect(command[4]).toEqual('--suffixes')
expect(command[5]).toEqual('php')

command = phpmd(
{
exclude: '/node_modules/'
},
'docroot'
)
expect(command[6]).toEqual('--exclude')
expect(command[7]).toEqual('/node_modules/')
})
Loading