File size: 5,585 Bytes
2e6b65c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# Code Quality & Linting Implementation Plan

## Overview
Establish comprehensive linting and code quality standards to catch issues early and maintain consistency across the codebase.

## Phase 1: golangci-lint Setup (Week 1)

### 1.1 Configuration File
**File**: `.golangci.yml`

```yaml
run:
  timeout: 5m
  go: '1.24'
  skip-dirs:
    - management-center
    - kiro-gateway

linters:
  enable:
    # Default
    - errcheck
    - gosimple
    - govet
    - ineffassign
    - staticcheck
    - unused
    # Additional
    - bodyclose
    - dogsled
    - dupl
    - exhaustive
    - goconst
    - gocritic
    - gofmt
    - goimports
    - gomnd
    - goprintffuncname
    - gosec
    - misspell
    - nakedret
    - noctx
    - nolintlint
    - prealloc
    - revive
    - stylecheck
    - unconvert
    - unparam
    - whitespace

linters-settings:
  gocritic:
    enabled-tags:
      - performance
      - style
      - experimental
    disabled-checks:
      - wrapperFunc
      - dupImport

  revive:
    rules:
      - name: unexported-return
        disabled: false
      - name: exported
        disabled: false
      - name: package-comments
        disabled: true

  gomnd:
    settings:
      mnd:
        checks:
          - argument
          - case
          - condition
          - operation
          - return
        ignored-numbers:
          - '0'
          - '1'
          - '2'
          - '10'
          - '60'
          - '100'

  dupl:
    threshold: 100

  gosec:
    excludes:
      - G104  # Audit errors not checked (handled by errcheck)

issues:
  exclude-rules:
    # Exclude init() function warnings in translator registrations
    - path: internal/translator/.*/init\.go
      linters:
        - gochecknoinits

    # Exclude underscore variable warnings in test files
    - path: _test\.go
      linters:
        - errcheck

    # Exclude long function warnings in handlers (will refactor separately)
    - path: internal/api/handlers/
      linters:
        - funlen
        - gocognit

  exclude-use-default: false
  max-issues-per-linter: 0
  max-same-issues: 0
```

### 1.2 Makefile Targets
**File**: `Makefile` (add to existing)

```makefile
.PHONY: lint lint-fix lint-install

lint-install:
	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

lint:
	golangci-lint run ./...

lint-fix:
	golangci-lint run --fix ./...

# Pre-commit hook
lint-precommit:
	@echo "#!/bin/sh" > .git/hooks/pre-commit
	@echo 'golangci-lint run --fast ./...' >> .git/hooks/pre-commit
	@chmod +x .git/hooks/pre-commit
	@echo "Pre-commit hook installed"
```

### 1.3 Initial Cleanup Tasks

- [ ] Fix all `goimports` issues (import ordering)
- [ ] Fix `gofmt` formatting inconsistencies
- [ ] Add missing error checks (`errcheck`)
- [ ] Remove unused variables and imports (`unused`)
- [ ] Fix `misspell` typos
- [ ] Address `gosec` security warnings
- [ ] Fix `staticcheck` issues

## Phase 2: GitHub Actions Integration (Week 1)

**File**: `.github/workflows/lint.yml`

```yaml
name: Lint

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main, develop]

jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: '1.24'

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v6
        with:
          version: latest
          args: --timeout=5m
          only-new-issues: true
```

## Phase 3: Python Linting (kiro-gateway)

**File**: `kiro-gateway/.pylintrc` or `kiro-gateway/pyproject.toml`

```toml
[tool.ruff]
target-version = "py311"
line-length = 100

[tool.ruff.lint]
select = [
    "E",   # pycodestyle errors
    "F",   # Pyflakes
    "I",   # isort
    "N",   # pep8-naming
    "W",   # pycodestyle warnings
    "UP",  # pyupgrade
    "B",   # flake8-bugbear
    "C4",  # flake8-comprehensions
    "SIM", # flake8-simplify
]
ignore = ["E501"]  # Line too long (handled by formatter)

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.mypy]
python_version = "3.11"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
```

## Phase 4: TypeScript/React Linting (management-center)

**File**: `management-center/eslint.config.js`

```javascript
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';

export default [
  js.configs.recommended,
  {
    files: ['**/*.{ts,tsx}'],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: './tsconfig.json',
      },
    },
    plugins: {
      '@typescript-eslint': tsPlugin,
      'react-hooks': reactHooks,
      'react-refresh': reactRefresh,
    },
    rules: {
      ...tsPlugin.configs.recommended.rules,
      ...tsPlugin.configs['recommended-requiring-type-checking'].rules,
      ...reactHooks.configs.recommended.rules,
      'react-refresh/only-export-components': 'warn',
      '@typescript-eslint/explicit-function-return-type': 'off',
      '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
    },
  },
];
```

## Success Metrics

- [ ] Zero linting errors in CI
- [ ] All new code passes linting on PR
- [ ] Pre-commit hooks installed for all contributors
- [ ] Linting time < 2 minutes for full codebase

## Estimated Effort

- **Week 1**: Setup and initial cleanup (16 hours)
- **Ongoing**: Maintenance as part of PR reviews