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AI,MAClC,IAAK,GAAS,EAAM,SAAS,GACzB,MAER,CAEJ,EAAO,MAAK,EAAI,MAAM,uBAAuB,EAAM,EAAW,kBAAoB,GAAI,EAAY,EAAY,gBAAgB,MAAO,GAAM,GAGnJ,EAAK,OAAO,GAAS,KAAK,EAC9B,CACJ,CACA,OAAO,CA7BP,OALI,QAAQ,MAAM,uDAAwD,EAmC9E,CACA,UAAA,CAAW,GACP,MAAM,GAAa,EAAI,YAAY,0BAA0B,GAAM,IAC/D,IAAK,MAAM,KAAQ,QAAQ,gBAAiB,CACxC,MAAM,EAAa,KAAK,KAAK,EAAG,GAChC,GAAI,GAAG,WAAW,GACd,OAAO,CAEf,CACgB,IAGpB,IAAK,EACD,OAGJ,OADe,KAAK,MAAM,GAAG,aAAa,EAAY,QAE1D,CACA,gBAAA,GACI,MAAM,QAAE,EAAO,QAAE,GAAY,KAAK,OAOlC,OANc,GAAG,KAAK,EAAS,IACvB,EACE,CAAE,OAAQ,MAAM,QAAQ,GAAW,EAAU,CAAC,IAC9C,CAAC,EACP,IAAK,KAAK,OAAO,cAER,KAAK,GAAM,KAAK,KAAK,KAAK,OAAO,YAAa,IAC/D,CACA,OAAA,GACI,KAAK,QAAQ,SACjB,EAEJ,QAAQ,OAAS","file":"/npm/pyright-lint@0.0.4/dist/linter.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/pyright-lint@0.0.4/dist/linter.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n    if (k2 === undefined) k2 = k;\n    var desc = Object.getOwnPropertyDescriptor(m, k);\n    if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n      desc = { enumerable: true, get: function() { return m[k]; } };\n    }\n    Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n    if (k2 === undefined) k2 = k;\n    o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n    Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n    o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n    if (mod && mod.__esModule) return mod;\n    var result = {};\n    if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n    __setModuleDefault(result, mod);\n    return result;\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Linter = exports.Severity = exports.pyrightPath = exports.configFileNames = void 0;\nconst service_1 = require(\"@zzzen/pyright-internal/dist/analyzer/service\");\nconst commandLineOptions_1 = require(\"@zzzen/pyright-internal/dist/common/commandLineOptions\");\nconst pathUtils_1 = require(\"@zzzen/pyright-internal/dist/common/pathUtils\");\nconst realFileSystem_1 = require(\"@zzzen/pyright-internal/dist/common/realFileSystem\");\nconst pyrightFileSystem_1 = require(\"@zzzen/pyright-internal/dist/pyrightFileSystem\");\nconst fs = __importStar(require(\"fs\"));\nconst path = __importStar(require(\"path\"));\nexports.configFileNames = [\"pyright-lint.config.json\"];\nconst fg = __importStar(require(\"fast-glob\"));\nconst rules_1 = __importDefault(require(\"./rules\"));\nconst console_1 = require(\"@zzzen/pyright-internal/dist/common/console\");\nconst positionUtils_1 = require(\"@zzzen/pyright-internal/dist/common/positionUtils\");\nconst ast_1 = require(\"./utils/ast\");\nexports.pyrightPath = require\n    .resolve(\"pyright/package.json\")\n    .replace(/package\\.json$/, \"\");\n//https:github.com/microsoft/pyright/blob/aad650ec373a9894c6f13490c2950398095829c6/packages/pyright/index.js#L6\nglobal.__rootDirectory = path.join(exports.pyrightPath, \"dist\");\nvar Severity;\n(function (Severity) {\n    Severity[\"Error\"] = \"error\";\n    Severity[\"Warning\"] = \"warning\";\n})(Severity = exports.Severity || (exports.Severity = {}));\nclass Linter {\n    constructor(option) {\n        this.ignoreLinesCache = new WeakMap();\n        this.option = option;\n        this.init();\n    }\n    init() {\n        const dir = this.option.projectRoot;\n        const fileSystem = new pyrightFileSystem_1.PyrightFileSystem((0, realFileSystem_1.createFromRealFileSystem)(new console_1.NullConsole()));\n        const service = new service_1.AnalyzerService(dir, fileSystem, {});\n        const options = new commandLineOptions_1.CommandLineOptions(dir, false);\n        service.setOptions(options);\n        this.service = service;\n        const config = this.readConfig(dir);\n        if (!config) {\n            // throw new Error(\"no config found for \" + dir);\n            console.log(\"no config found for \" + dir);\n        }\n        this.config = config || { include: [] };\n    }\n    getIgnoresOfFile(filePath) {\n        const parseResult = this.service.backgroundAnalysisProgram.program\n            .getSourceFile(filePath)\n            ?.getParseResults();\n        if (!parseResult) {\n            return undefined;\n        }\n        if (parseResult && this.ignoreLinesCache.has(parseResult)) {\n            return this.ignoreLinesCache.get(parseResult);\n        }\n        const ignoreLines = new Map();\n        for (let pos = 0; pos < parseResult.tokenizerOutput.tokens.count; pos++) {\n            const token = parseResult.tokenizerOutput.tokens.getItemAt(pos);\n            if (!token.comments) {\n                continue;\n            }\n            for (const comment of token.comments) {\n                const match = comment.value.match(/^\\s*pyright-lint:\\s*ignore(\\s*\\[([\\s*\\w-,]*)\\]|\\s|$)/);\n                if (!match) {\n                    continue;\n                }\n                const rules = match[2].split(\",\").map((x) => x.trim());\n                const line = (0, positionUtils_1.convertOffsetToPosition)(comment.start, parseResult.tokenizerOutput.lines).line;\n                ignoreLines.set(line, rules);\n            }\n        }\n        this.ignoreLinesCache.set(parseResult, ignoreLines);\n        return ignoreLines;\n    }\n    lintFiles() {\n        const files = this.getMatchingFiles();\n        if (!files.length) {\n            throw new Error(\"no files found for \" + this.option.projectRoot);\n        }\n        let errors = [];\n        for (const file of files) {\n            errors = errors.concat(this.lintFile(file) || []);\n        }\n        return errors;\n    }\n    setFileOpen(path, version, content) {\n        this.service.setFileOpened(path, version, content);\n        this.forceAnalysis();\n    }\n    setFileClose(path) {\n        this.service.setFileClosed(path);\n    }\n    forceAnalysis() {\n        return this.service.backgroundAnalysisProgram.program.analyze();\n    }\n    lintFile(file) {\n        const errors = [];\n        const program = this.service.backgroundAnalysisProgram.program;\n        const sourceFile = program.getSourceFile(file);\n        const parseResult = sourceFile?.getParseResults();\n        const ast = parseResult?.parseTree;\n        if (!sourceFile || !ast) {\n            console.error(\"Ast not found. Maybe file is not included by pyright\", file);\n            return;\n        }\n        if (parseResult.tokenizerOutput.typeIgnoreAll) {\n            return;\n        }\n        for (const [ruleName, rule] of Object.entries(rules_1.default)) {\n            const active = this.config[ruleName];\n            if (active) {\n                const context = {\n                    id: ruleName,\n                    options: [],\n                    program,\n                    report: (descriptor) => {\n                        const pos = (0, ast_1.getStartPositionFromReport)(descriptor, parseResult.tokenizerOutput.lines);\n                        if (parseResult.tokenizerOutput.typeIgnoreLines.has(pos.line) ||\n                            parseResult.tokenizerOutput.pyrightIgnoreLines.has(pos.line)) {\n                            return;\n                        }\n                        const ignoreLines = this.getIgnoresOfFile(file);\n                        if (ignoreLines) {\n                            if (ignoreLines.has(pos.line)) {\n                                const rules = ignoreLines.get(pos.line);\n                                if (!rules || rules.includes(ruleName)) {\n                                    return;\n                                }\n                            }\n                        }\n                        errors.push((0, ast_1.formatErrorDescriptor)(file, sourceFile.getFileContent() || \"\", descriptor, parseResult.tokenizerOutput.lines, rule));\n                    },\n                };\n                rule.create(context).walk(ast);\n            }\n        }\n        return errors;\n    }\n    readConfig(dir) {\n        const configPath = (0, pathUtils_1.forEachAncestorDirectory)(dir, (d) => {\n            for (const name of exports.configFileNames) {\n                const configPath = path.join(d, name);\n                if (fs.existsSync(configPath)) {\n                    return configPath;\n                }\n            }\n            return undefined;\n        });\n        // TODO: support `tools.pyright-lint` in pyproject.toml\n        if (!configPath) {\n            return undefined;\n        }\n        const config = JSON.parse(fs.readFileSync(configPath, \"utf8\"));\n        return config;\n    }\n    getMatchingFiles() {\n        const { include, exclude } = this.config;\n        const files = fg.sync(include, {\n            ...(exclude\n                ? { ignore: Array.isArray(exclude) ? exclude : [exclude] }\n                : {}),\n            cwd: this.option.projectRoot,\n        });\n        return files.map((f) => path.join(this.option.projectRoot, f));\n    }\n    dispose() {\n        this.service.dispose();\n    }\n}\nexports.Linter = Linter;\n"]}