Skip to content
Open
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
1 change: 1 addition & 0 deletions .boilerplate-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d769f2d57af542dd1ef245dc3594d9e5ac6e31dc
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ on:

jobs:
release:
name: '/'
name: 'Release'
uses: technology-studio/github-workflows/.github/workflows/_release.yml@main
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/resolve-yarn-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
resolve-yarn-lock-on-comment:
name: '/'
name: 'Resolve yarn.lock'
if: contains(github.event.comment.body, '/resolve yarn.lock')
uses: technology-studio/github-workflows/.github/workflows/_resolve-yarn-lock.yml@main
secrets: inherit
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarn git-hook

yarn -s lint-staged
1 change: 0 additions & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarn commitlint --edit || exec < /dev/tty && yarn txo-cz --hook > /dev/null 2>&1 || true

3 changes: 3 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.{js,jsx,ts,tsx}": "eslint --cache --max-warnings 0 --no-warn-ignored"
}
3 changes: 3 additions & 0 deletions .ncurc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dep": "dev,prod,peer"
}
2 changes: 1 addition & 1 deletion .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Copyright: Technology Studio
**/

module.exports = {
export default {
extends: [
'@txo/semantic-release',
],
Expand Down
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "--coverage", "false", "${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Debug Jest Tests with yarn",
"type": "node",
"request": "launch",
"runtimeExecutable": "yarn",
"args": ["test", "--runInBand", "--coverage=false", "${file}"],
"runtimeArgs": ["--inspect-brk"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
]
}
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 2 additions & 6 deletions __tests__/Tests/Lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/**
* @Author: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
* @Date: 2018-01-09T00:56:40+01:00
* @Copyright: Technology Studio
**/

const { FlatESLint } = require('eslint/use-at-your-own-risk')
import { ESLint } from 'eslint'

test('shoud not have lint issues', async () => {
const eslint = new FlatESLint()
const eslint = new ESLint()
const results = await eslint.lintFiles(['test/**/*.ts'])
const isWithoutError = results.every((result: { errorCount: number }) => result.errorCount === 0)
expect(isWithoutError).toBe(true)
Expand Down
9 changes: 8 additions & 1 deletion __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "../tsconfig-base.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"paths": {
"Config/*": [ "./__tests__/Config/*" ],
"Data/*": [ "./__tests__/Data/*" ],
"Utils/*": [ "./__tests__/Utils/*" ],
"src": [ "./src" ],
"src/*": [ "./src/*" ]
}
},
"include": [
"./**/*.ts"
Expand Down
4 changes: 1 addition & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
* @Copyright: Technology Studio
**/

const commitlintConfig = {
export default {
extends: [
'@txo/commitlint',
],
}

module.exports = commitlintConfig
1 change: 1 addition & 0 deletions eslint-ci-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
13 changes: 13 additions & 0 deletions eslint-ci.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ciRules from './eslint-ci-rules.json' with { type: 'json' }

export default (async function config() {
const { default: defaultConfigPromise } = await import('./eslint.config.js')
const defaultConfig = await defaultConfigPromise
return [
...defaultConfig,
{
files: ['**/*.ts', '**/*.tsx'],
rules: ciRules.reduce((acc, rule) => ({ ...acc, [rule]: 'warn' }), {}),
},
]
})()
54 changes: 26 additions & 28 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
const txoConfig = require('eslint-config-txo-typescript')
const txoPlugin = require('./lib')

/** @type {import('eslint').Linter.FlatConfig[]} */
const config = [
...txoConfig.default,
{
files: ['**/*.ts', '**/*.tsx'],
plugins: {
'@txo/typescript': txoPlugin,
},
rules: {
'@txo/typescript/correct-log-path': 'error',
},
},
{
files: ['test/**/*.ts'],
languageOptions: {
parserOptions: {
project: './test/tsconfig.json',
import txoPlugin from './lib/index.js'
export default (async function config() {
const txoPackageConfigList = await import('eslint-config-txo-package-typescript')
return [
...txoPackageConfigList.configList,
{
files: ['**/*.ts', '**/*.tsx'],
plugins: {
'@txo/typescript': txoPlugin,
},
rules: {
'@txo/typescript/correct-log-path': 'error',
},
},
settings: {
'import/resolver': {
typescript: {
{
files: ['test/**/*.ts'],
languageOptions: {
parserOptions: {
project: './test/tsconfig.json',
},
},
settings: {
'import/resolver': {
typescript: {
project: './test/tsconfig.json',
}
}
}
}
}
]

module.exports = config
},
]
})()
15 changes: 8 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* @Copyright: Technology Studio
**/

const { compilerOptions } = require('./tsconfig.json');
import { pathsToModuleNameMapper } from 'ts-jest'
import { defaults } from 'jest-config'

const { defaults } = require('jest-config');
import tsconfig from './__tests__/tsconfig.json' with { type: 'json' }

module.exports = {
export default {
preset: 'ts-jest',
cache: true,
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
testEnvironment: 'node',
testMatch: [
'<rootDir>/__tests__/Tests/**/?(*.)(spec|test).ts'
],
transformIgnorePatterns: [
'/node_modules/(?!@txo).+\\.js$'
],
testPathIgnorePatterns: [
'/node_modules/'
],
Expand All @@ -28,7 +28,8 @@ module.exports = {
],
transform: {
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: './__tests__/tsconfig.json'
tsconfig: '<rootDir>/__tests__/tsconfig.json'
}]
},
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: '<rootDir>/' }),
}
30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.1",
"description": "Technology Studio - Eslint typescript plugin",
"main": "lib/index.js",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/technology-studio/eslint-plugin-txo-typescript.git"
Expand All @@ -15,18 +16,23 @@
"license": "MIT",
"private": false,
"scripts": {
"build": "yarn compile",
"build:clean": "yarn rimraf lib",
"build:lib": "yarn tsc",
"build:watch": "yarn tsc --watch",
"build": "yarn build:clean && yarn build:lib",
"compare-boilerplate-version": "./scripts/compare-boilerplate-version.sh",
"coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
"lint:ci": "yarn eslint -c eslint-ci.config.js --cache . && yarn txo-eslint ccr --cache",
"lint:fix": "eslint . --fix",
"lint": "eslint --max-warnings 0 .",
"fixcode": "eslint . --fix",
"git-hook": "yarn -s lint",
"ncu-all": "ncu -i",
"compile": "tsc",
"prepare": "husky && yarn build",
"sanity": "yarn lint:ci && yarn test --coverage && tsc --noEmit && yarn outdated && echo 'success'",
"print-txo-packages": "yarn list 2> /dev/null|grep @txo|sed 's/.*\\(@txo[^@]*\\)@^*\\([^ ]*\\).*/\\1@\\2/g'|sort|uniq",
"sanity": "yarn build && yarn lint:ci && tsc --noEmit && yarn test --coverage && yarn compare-boilerplate-version && echo 'success'",
"semantic-release": "semantic-release",
"test:watch": "concurrently \"yarn build:watch\" \"yarn test --watch\"",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"lint:ci": "yarn lint",
"type-check": "tsc --noEmit"
"type-check": "tsc --noEmit",
"update-boilerplate-version": "./scripts/update-boilerplate-version.sh"
},
"engines": {
"node": ">=18.0.0"
Expand All @@ -35,14 +41,16 @@
"devDependencies": {
"@txo/commitlint": "^1.0.24",
"@txo/semantic-release": "^2.0.10",
"@txo/tsconfig-cjs": "^2.0.0",
"@types/eslint": "^8.56.12",
"@txo/tsconfig": "^2.0.0",
"@types/eslint": "^9.6.1",
"@types/jest": "^29.5.14",
"@types/node": "^22.18.6",
"eslint-config-txo-typescript": "^4.0.70",
"eslint-config-txo-package-typescript": "^1.0.31",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^16.2.0",
"npm-check-updates": "^18.3.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.4.4",
"typescript": "^5.9.2"
}
Expand Down
14 changes: 14 additions & 0 deletions scripts/compare-boilerplate-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

LATEST=$(
git ls-remote -h git@github.com:technology-studio/test-boilerplate-typescript.git |
grep refs/heads/master | awk '{ print $1 }'
)
CURRENT=$(cat .boilerplate-version)
echo "Latest version: $LATEST"
echo "Current version: $CURRENT"
if [ "$LATEST" != "$CURRENT" ]; then
echo "🚫 Boilerplate versions do not match! Check test-boilerplate-typescript repo for new changes."
exit 1
fi
echo "✅ Boilerplate versions match!"
8 changes: 8 additions & 0 deletions scripts/update-boilerplate-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

LATEST=$(
git ls-remote -h git@github.com:technology-studio/test-boilerplate-typescript.git |
grep refs/heads/master | awk '{ print $1 }'
)
echo $LATEST > .boilerplate-version
echo "Updated boilerplate version to: $LATEST"
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/**
* @Author: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
* @Date: 2020-06-10T16:06:00+02:00
* @Copyright: Technology Studio
**/

module.exports = {
import correctLogPath from './rules/correct-log-path.js'

export default {
rules: {
'correct-log-path': require('./rules/correct-log-path'),
'correct-log-path': correctLogPath,
},
}
17 changes: 9 additions & 8 deletions src/rules/correct-log-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
relative,
resolve,
} from 'path'
import { type Rule } from 'eslint'
import type { Rule } from 'eslint'
import { readFileSync } from 'fs'

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- we know that package.json exists and we know can have name
const packageJson = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json'), 'utf8')) as { name?: string }

const logPathRule: Rule.RuleModule = {
Expand All @@ -22,26 +23,26 @@ const logPathRule: Rule.RuleModule = {
},
fixable: 'code',
},
create (context: Rule.RuleContext): Rule.RuleListener {
create(context: Rule.RuleContext): Rule.RuleListener {
return {
NewExpression (node): void {
NewExpression(node): void {
if (node.callee.type === 'Identifier' && node.callee.name === 'Log') {
const relativePath = relative(process.cwd(), context.filename)
const packageName = packageJson.name
const { name: packageName } = packageJson
let logPath = relativePath.replace(/\.[^/.]+$/, '')
if (packageName != null && packageName !== 'MobileApp') {
logPath = `${packageName.replace('/', '.')}.${logPath}`
}
const logPathParts = logPath.split(sep)
const logName = logPathParts.join('.')
const logArg = node.arguments[0]
if (logArg != null && logArg.type === 'Literal' && typeof logArg.value === 'string') {
const { arguments: [logArg] } = node
if (logArg.type === 'Literal' && typeof logArg.value === 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why null check was removed ?

const expectedLogArg = logName
if (logArg.value !== expectedLogArg) {
context.report({
node: logArg,
message: `Log path should be ${expectedLogArg}.`,
fix (fixer) {
fix(fixer) {
return fixer.replaceText(logArg, `'${expectedLogArg}'`)
},
})
Expand All @@ -53,4 +54,4 @@ const logPathRule: Rule.RuleModule = {
},
}

module.exports = logPathRule
export default logPathRule
2 changes: 1 addition & 1 deletion test/LogMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

export class Log {
logPath: string
constructor (logPath: string) {
constructor(logPath: string) {
this.logPath = logPath
}
}
Loading
Loading