ifc-language-server/node_modules/@stylistic/eslint-plugin/dist/rules/one-var-declaration-per-line.js
Ryan Schultz 8afacf268a Implemented a working Language Server Protocol (LSP) for IFC files with:
- Hover provider showing entity information and type
- Go-to-definition (F12) for entity references
- Basic IFC file validation (ISO-10303-21 header check)
- Entity parsing with regex-based detection
- Proper CommonJS module system (avoiding ES module issues)

This replaces the broken baseline from ifc-developer-tools which had:
- Non-functional ES module configuration
- Circular dependency issues
- Parser crashes
- Non-working PositionVisitor

Built on Microsoft's LSP example template for a clean, maintainable foundation.

Next: Add hierarchical entity dependency tree in hover tooltip."
2025-12-07 10:20:07 -06:00

57 lines
1.5 KiB
JavaScript

'use strict';
var utils = require('../utils.js');
require('eslint-visitor-keys');
require('espree');
require('estraverse');
var oneVarDeclarationPerLine = utils.createRule({
name: "one-var-declaration-per-line",
package: "js",
meta: {
type: "layout",
docs: {
description: "Require or disallow newlines around variable declarations"
},
schema: [
{
type: "string",
enum: ["always", "initializations"]
}
],
fixable: "whitespace",
messages: {
expectVarOnNewline: "Expected variable declaration to be on a new line."
}
},
create(context) {
const always = context.options[0] === "always";
function isForTypeSpecifier(keyword) {
return keyword === "ForStatement" || keyword === "ForInStatement" || keyword === "ForOfStatement";
}
function checkForNewLine(node) {
if (isForTypeSpecifier(node.parent.type))
return;
const declarations = node.declarations;
let prev;
declarations.forEach((current) => {
if (prev && prev.loc.end.line === current.loc.start.line) {
if (always || prev.init || current.init) {
context.report({
node,
messageId: "expectVarOnNewline",
loc: current.loc,
fix: (fixer) => fixer.insertTextBefore(current, "\n")
});
}
}
prev = current;
});
}
return {
VariableDeclaration: checkForNewLine
};
}
});
module.exports = oneVarDeclarationPerLine;